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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.