|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hey All,
After searching I found this regex to remove img tags from a post, but running it is giving me an error, being a total noob with regex i have no idea what the heck is wrong.... heres the whole script as its tiny: <?php $html = " hello ".'<img src="/articles-blog/imgs/paul-fat.jpg" alt="" width="272" height="289" align="left">'. " Paul! "; $html = preg_replace('</?img((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>', '', $html); echo $html; ?> Any appreciated. TIA, Ryan ------ - The faulty interface lies between the chair and the keyboard. - Creativity is great, but plagiarism is faster! - Smile, everyone loves a moron. :-) __________________________________________________ __________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Ryan A wrote:
> Hey All, > > After searching I found this regex to remove img tags from a post, but running it is giving me an error, being a total noob with regex i have no idea what the heck is wrong.... heres the whole script as its tiny: > > <?php > > $html = " hello ".'<img src="/articles-blog/imgs/paul-fat.jpg" alt="" width="272" height="289" align="left">'. " Paul! "; > > $html = preg_replace('</?img((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>', '', $html); > > echo $html; > ?> > > Any appreciated. > > TIA, > Ryan > > > ------ > - The faulty interface lies between the chair and the keyboard. > - Creativity is great, but plagiarism is faster! > - Smile, everyone loves a moron. :-) > > > > > __________________________________________________ __________________________________ > Never miss a thing. Make Yahoo your home page. > http://www.yahoo.com/r/hs why not a simple: $html = preg_replace('#(<[/]?img.*>)#U', '', $html); ? - Tul |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
M. Sokolewicz wrote:
> Ryan A wrote: >> Hey All, >> >> After searching I found this regex to remove img tags from a post, but >> running it is giving me an error, being a total noob with regex i have >> no idea what the heck is wrong.... heres the whole script as its tiny: >> >> <?php >> >> $html = " hello ".'<img src="/articles-blog/imgs/paul-fat.jpg" alt="" >> width="272" height="289" align="left">'. " Paul! "; >> >> $html = >> preg_replace('</?img((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>', >> '', $html); >> >> echo $html; >> ?> >> >> Any appreciated. >> >> TIA, >> Ryan >> >> >> ------ >> - The faulty interface lies between the chair and the keyboard. >> - Creativity is great, but plagiarism is faster! >> - Smile, everyone loves a moron. :-) >> >> >> >> >> >> __________________________________________________ __________________________________ >> >> Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs > > > why not a simple: > $html = preg_replace('#(<[/]?img.*>)#U', '', $html); > ? Wouldn't your example do this? <p><img src="..." /><br /> some description</p> ^--catch from here to here ??-------------^ Would it not be better if the .* was [^>]+ instead. Wouldn't the .* catch an > even if it was like this? Jim > > - Tul > |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Jim Lucas wrote:
> M. Sokolewicz wrote: >> Ryan A wrote: >>> Hey All, >>> >>> After searching I found this regex to remove img tags from a post, >>> but running it is giving me an error, being a total noob with regex i >>> have no idea what the heck is wrong.... heres the whole script as its >>> tiny: >>> >>> <?php >>> >>> $html = " hello ".'<img src="/articles-blog/imgs/paul-fat.jpg" alt="" >>> width="272" height="289" align="left">'. " Paul! "; >>> >>> $html = >>> preg_replace('</?img((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>', >>> '', $html); >>> >>> echo $html; >>> ?> >>> >>> Any appreciated. >>> >>> TIA, >>> Ryan >>> >>> >>> ------ >>> - The faulty interface lies between the chair and the keyboard. >>> - Creativity is great, but plagiarism is faster! >>> - Smile, everyone loves a moron. :-) >>> >>> >>> >>> >>> >>> __________________________________________________ __________________________________ >>> >>> Never miss a thing. Make Yahoo your home page. >>> http://www.yahoo.com/r/hs >> >> >> why not a simple: >> $html = preg_replace('#(<[/]?img.*>)#U', '', $html); >> ? > > Wouldn't your example do this? > > <p><img src="..." /><br /> some description</p> > ^--catch from here to here ??-------------^ > > Would it not be better if the .* was [^>]+ instead. Wouldn't the .* > catch an > even if it was like this? > > Jim > >> >> - Tul >> > The U modifier prevents that, it makes the expression ungreedy. So unless the OP has a tag with an > embedded in it, it should be fine. - Tul |
|
![]() |
| Outils de la discussion | |
|
|