Jump to content

Recommended Posts

Hi,

 

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

Matt

Link to comment
https://forums.phpfreaks.com/topic/269108-no-success-in-removing/
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.

 

Thanks

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.

<?php
$myIntro= '<p>My Paragraph</p>\r\n<p> </p>';
$myIntro = rtrim($myIntro, '<p> </p>');
echo $myIntro;

 

Thanks Jessica. Unfortunately it did not work. I'm thinking that maybe the " " is not actually white space but hidden characters stored in the db?...

*eyeroll*.

 

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>"

AND

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

 

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

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.

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.