Forum Moderators: coopster

Message Too Old, No Replies

Leave quotes in img tag when using strip tags

         

brandon0401

7:53 pm on Sep 20, 2007 (gmt 0)

10+ Year Member



Hey guys, using strip_tags to strip a bunch of stuff out but what I want to leave is " quotes in tags

there is a img tag

<img vspace="4" hspace="4" border="1" align=right alt="" src="http://www.example.com/image.gif"/>

after running

I am left with

<img vspace=4 hspace=4 border=1 align=right alt= src=http://www.example.com/image.gif />

how can I leave the closing "" around the tags, ie alt=""?

Here is my strip tag cmd
while($input!= strip_tags($input, '<b><i><em><strong><img><br><blockquote><object><param><embed><p><quote>'))

{

$input = strip_tags($input, '<b><i><em><strong><img><br><blockquote><object><param><embed><p><quote>');

}

not working, thanks!

B

[edited by: eelixduppy at 8:47 pm (utc) on Sep. 20, 2007]
[edit reason] please use example.com [/edit]

joelgreen

5:23 pm on Sep 21, 2007 (gmt 0)

10+ Year Member



what php version? It is working fine on 5.0.4

brandon0401

10:48 pm on Sep 23, 2007 (gmt 0)

10+ Year Member



4.4.7

is the version im using

still taking away " " quotes

thanks in advance

brandon0401

1:42 am on Sep 25, 2007 (gmt 0)

10+ Year Member



bump thanks

coopster

7:41 pm on Sep 25, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I just tested on 4.4.7 without any issue. Are you certain there isn't something else in your code causing you problems? Here was my test case, you try the same and see if your code comes out exactly the same ...

<pre> 
<?php
$input = '<img vspace="4" hspace="4" border="1" align=right alt="" src="http://www.example.com/image.gif"/>' . "\n";
print htmlentities($input);
while($input!= strip_tags($input, '<b><i><em><strong><img><br><blockquote><object><param><embed><p><quote>')) {
$input = strip_tags($input, '<b><i><em><strong><img><br><blockquote><object><param><embed><p><quote>');
}
print htmlentities($input);
exit;
?>
</pre>

brandon0401

6:49 am on Sep 26, 2007 (gmt 0)

10+ Year Member



well there is text and other things around it not just that...

what are you left with?

coopster

10:34 am on Sep 28, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Rendered in the browser:

<img vspace="4" hspace="4" border="1" align=right alt="" src="http://www.example.com/image.gif"/>

<img vspace="4" hspace="4" border="1" align=right alt="" src="http://www.example.com/image.gif"/>

If I "View Source":

<pre> 
&lt;img vspace=&quot;4&quot; hspace=&quot;4&quot; border=&quot;1&quot; align=right alt=&quot;&quot; src=&quot;http://www.example.com/image.gif&quot;/&gt;

&lt;img vspace=&quot;4&quot; hspace=&quot;4&quot; border=&quot;1&quot; align=right alt=&quot;&quot; src=&quot;http://www.example.com/image.gif&quot;/&gt;

brandon0401

6:36 pm on Oct 2, 2007 (gmt 0)

10+ Year Member



hmm

what version of PHP?

Mine strips out the ""

and im left with

<img vspace=4 hspace=4 border=1 align=right alt= src=http://www.example.com/image.gif />

You are using the same strip tags params?

brandon0401

6:02 am on Oct 3, 2007 (gmt 0)

10+ Year Member



anything? much appreciated, seems easy not sure whats up, thanks

coopster

10:57 pm on Oct 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what version of PHP?

As I stated earlier, same version:

I just tested on 4.4.7 without any issue.

You are using the same strip tags params?

I cut and pasted your code!

You must have something else wrong. As I stated before, did you try just the code in the test case that I posted. Try that, and that alone to see if it works. If it does, then you have something else causing your issue.

brandon0401

5:14 am on Oct 4, 2007 (gmt 0)

10+ Year Member



think I know why, saw another str replace

but will it work if I dont use htmlentities?

does that have to be on to translate to page later as well? thanks

coopster

4:10 pm on Oct 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



No, you do not need to use htmlentities. I used it so I could dump the string to the browser to compare the before and after.