Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Replacing <p> tags

$
0
0

Hi,

I'm trying to replace <p> tags and replace it with a contenteditable div.

$newpost = str_replace("<p>", "<div contenteditable=\"true\"><p>", $post);

This code works fine however I'm using javascript setInterval to periodically update to a database through ajax and while it doesn't conflict with javascript when I refresh the page it inserts a second string replace.

eg.
On first refresh it enters

<div contenteditable="true"><p>

On second refresh it enters

<div contenteditable="true"><div contenteditable="true"><p>

On third refresh it enters

<div contenteditable="true"><div contenteditable="true"><div contenteditable="true"><p>

I've tried replacing the <p> with <P> or <p class="paragraph"> and str_replace instead of str_ireplace but I still get the same result.

Does anyone know of any way I can only have it replace once?


Viewing all articles
Browse latest Browse all 13200

Trending Articles