Paul Jung escribió:
Quote:
how to cut a certain group of words in a string, for example,
"<img src='images/smiles/grin.gif' smilietext=':grin:' border='0'
style='vertical-align:middle' alt=':grin:' title=':grin:' />"
"<img src='images/smiles/smile.gif' smilietext=': smile:' border='0'
style='vertical-align:middle' alt=': smile:' title=': smile:' />"
¡*..
from a forum comment.
>
I tried this:
$subject =$row_Recordset2['pagetext']
$pattern="/<img src='images\/smiles\/[a-zA-Z]+\.gif' smilietext=':[a-zA-Z]:'
border='0' style='vertical-align:middle' alt=':[a-zA-Z]:' title=':[a-zA-Z]:'
\/>/";
$result = preg_replace($pattern,"",$subject);
But I failed, I am new to PHP, please help. Thanks very much in advance.
A couple of tips:
- You can strip HTML tags with strip_tags() or filter_var().
- You can sanitize HTML output with a third-party library like HTML
Purifier:
http://htmlpurifier.org/
If you merely want to remove <imgtags then...
Quote:
logically, is it a better way to search for all what is inside the <img ...
/tag (including numbers) and replace them with ""?
I will write: $pattern="/<img [a-zA-Z][0-9]>\/>/", is it correct? Thank you
for your help.
.... try something like:
$pattern = '@<img\s.*/?>@Uis'; // Not tested
Just be aware that regexp based HTML parsing tends to fail when faced to
invalid HTML.
--
--
http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
http://bits.demogracia.com
-- Mi web de humor al baño María:
http://www.demogracia.com
--