Jump to content

No Success In Removing <P> </p>


Recommended Posts



I've been trying to remove a suborn <p> </p> which sometimes appears at the bottom of a database entry after the CMS in use strips out 'unsafe' HTML.


The value returned from my SQL string is:


(8, 'Title', 'Alias', '', '<p>My Paragraph</p>\r\n<p> </p>', '', 1);


I've tried removing the unwanted <p> </p> using the code and find variations below, but still no success.

$myIntro= $db->intro;

$find = array('<p></p>','<p> </p>','<p> </p>',' ','\n');
$myIntro = str_ireplace($find,'', $myIntro);



Does anyone have any other approaches to try and strip this out from my string? I can't dump all <p> tags as I still need the rest for formatting.


Many thanks


Link to comment
Share on other sites

What do you mean "still no success"? Your code above seems to be able to strip out the unwanted tags in your example.


What's your criteria for "success"?


Hi seanlim,


Even though I run the code (above) the unwanted '<p> </p>' is still present in the variable and echoed to my page. It interferes with layout and alignment.



Link to comment
Share on other sites

You can strip out HTML of your string using

$string = strip_tags($myIntro);


or you can str_replace one tag at the time

$find = array('<p>', '</p>');


Thanks drisate,


Unfortunately that solution will not work as I still need to keep the other <p> tags for correct formatting. I only wish to target the <p> tags with a blank space.

Link to comment
Share on other sites



Do a var_dump and post the contents of it. Var_dump is not to remove strings.


The biggest problem is that you apparently don't see a difference between

"<td><p>My Paragraph </p><p> </p></td>"


"<p>My Paragraph</p>\r\n<p> </p>"


Which IS the real string you're working with? God.

Link to comment
Share on other sites

Thanks Jessica. I am perfectly aware of var_dump. In this case it does not prove useful as the character which is held within the <p> </p> does not render. I have since done further investigation into the mystery space and it is clear it is not actually 'white space' so I will work on another method to remove it. Allah.

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.

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.