You are here: Re: preg_match_all « PHP Language « IT news, forums, messages
Re: preg_match_all

Posted by Du on 05/27/05 05:35

try this

// $LS_LOOK_FOR_MASK='!<[^/].*?\sname="item_1".*?>!' ;

instead of .*? at the end ..... use [^>]*?

$LS_LOOK_FOR_MASK='!<[^/].*?\sname="item_1"[^>]*?>!' ;


i haven't test it out yet ... try it out, if it doesn't work let me know



"Mike M" <mike@nospam.mak.co.nz> wrote in message
news:429674e2@news.maxnet.co.nz...
> Hi
>
> I'm trying to extract from a line of HTML individual tags, using the
> "name"
> attribute to determine which tag to extract. What I'm getting seems to be
> a
> greedy match which isn't what I'm looking for.
>
> // source html line with rubbish tag for testing purposes
> $LS_HTML_LINE='<input type="text" value="456=tre" width=5 name="item_2"
> blah=wer checked id="abc" />This is not to be included</a><input
> type="checkbox" value="123=tre" name="item_1" checked />' ;
> // regular expression to use
> $LS_LOOK_FOR_MASK='!<[^/].*?\sname="item_1".*?>!' ;
> // run the regular expression
> preg_match($LS_LOOK_FOR, $LS_HTML_LINE, $LA_ALL_TAGS) ;
> // lets see what we've got
> print_r($LA_ALL_TAGS) ;
>
> Array
> (
> [0] => <input type="text" value="456=tre" width=5 name="item_2"
> blah=wer
> checked id="abc" />This is not to be included</a><input type="checkbox"
> value="123=tre" name="item_1" checked />
> )
>
> This is not what I'm after, the desired result is :
> <input type="checkbox" value="123=tre" name="item_1" checked />
>
> but when I do the same for item_2 I get the desired result
>
> $LS_LOOK_FOR_MASK='!<[^/].*?\sname="item_2".*?>!' ;
> preg_match($LS_LOOK_FOR, $LS_HTML_LINE, $LA_ALL_TAGS) ;
> print_r($LA_ALL_TAGS) ;
> Array
> (
> [0] => <input type="text" value="456=tre" width=5 name="item_2"
> blah=wer
> checked id="abc" />
> )
>
> This tells me that I'm missing something in the beginning of the regular
> expression, I've spent several hours hacking to no effect and Googling
> without seeing anything that seems to be what I'm after.
>
> I think that it's time to throw this one out to those more proficient with
> regular expressions. Any help would be greatly appreciated.
>
> Cheers
> Mike
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация