Jump to content

iterate through a string looking for all occurrences of a substring


johnmerlino

Recommended Posts

Hey all,

 

I have method like this:

 

echo tinymce_tag($post->body);

 

Basically the body property contains a string from database containing one or many paragraphs delimited by p tags:

 

<p>Hello World.</p>
<p>Goodbye World.</p>

 

I want to give all the paragraphs a class. This function will give the first p tag a class:

 

if ( ! function_exists('tinymce_tag')){
	function tinymce_tag($content = ''){

		$pos = strpos($content, '<p>');

		if($pos !== false){
			$content = substr_replace($content,' class="paragraph_styler"', 2, 0);
		}
		return $content;
	}
}

 

But I am not sure how to give all the p tags in the content variable a class.

 

Thanks for response.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.