Closed Thread Icon

Topic awaiting preservation: PREG_REPLACE and escaping HTML tags (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12815" title="Pages that link to Topic awaiting preservation: PREG_REPLACE and escaping HTML tags (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PREG_REPLACE and escaping HTML tags <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-15-2003 15:27

I couldn't find this is various searches, and realize I'm probably just not using the right keywords.

Anyways:

$code = preg_replace("<IMG height=23 src=\"images/printdoc.gif\" width=22 border=0>", "", $code);

I end up with '<>', since it doesn't seem to be escaping those characters. I'm not having any luck on getting it to strip everything. I need to do some more replacements that also involve HTML tags...

What am I missing? I looked up all the comments for preg_replace on php.net, but they didn't seem to help.

Thanks!

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-15-2003 15:47

Pugzly: This should work:

code:
$code = preg_replace("(<IMG height=23 src=\"images/printdoc.gif\" width=22 border=0> )si", "", $code);



but unless you were trying to do some more complex regular expression work:

code:
$code = preg_replace("(<IMG height=23 src=\"images/(.*)\" width=22 border=0> )si", "", $code);



then I'd recommend you use a string function.

[edit: So it would be something like:

code:
$code = str_replace("<IMG height=23 src=\"images/printdoc.gif\" width=22 border=0>", "", $code);



but it depends on your plans.]

___________________
Emps

FAQs: Emperor

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-15-2003 15:58

Basically doing some fairly simple web fetching and just need to strip out some unwanted tags, but can't strip them all (or I'd use strip_tags).

What's the 'si' do?

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-15-2003 16:11

Pugzly: si are pattern modifiers:
http://www.php.net/manual/en/pcre.pattern.modifiers.php

i means it checks both cases

s means that the dot will also match a newline - not technically necessary in this case but I tend to throw it in just in case something odd is going on.

___________________
Emps

FAQs: Emperor

« BackwardsOnwards »

Show Forum Drop Down Menu