|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello... I'm trying to write a regular expression to match the content
of a html tag. I need to match the content of <h1> i.e. <h1>Hello World</h1> <h1 class="red_background">Hello World</h1> <h1><img src="red.gif"/></h1> etc... can anyone me? Thanks!! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
..oO(nintesa)
>Hello... I'm trying to write a regular expression to match the content >of a html tag. > >I need to match the content of <h1> i.e. > ><h1>Hello World</h1> ><h1 class="red_background">Hello World</h1> ><h1><img src="red.gif"/></h1> > >etc... > >can anyone me? Try this pattern: #<h1[^>]*>(.+?)</h1># Micha |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Michael Fesser ha scritto:
> .oO(nintesa) > >> Hello... I'm trying to write a regular expression to match the content >> of a html tag. >> >> I need to match the content of <h1> i.e. >> >> <h1>Hello World</h1> >> <h1 class="red_background">Hello World</h1> >> <h1><img src="red.gif"/></h1> >> >> etc... >> >> can anyone me? > > Try this pattern: > > #<h1[^>]*>(.+?)</h1># > > Micha It's working!! thanks! |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
nintesa wrote:
> Hello... I'm trying to write a regular expression to match the content > of a html tag. > > I need to match the content of <h1> i.e. > > <h1>Hello World</h1> > <h1 class="red_background">Hello World</h1> > <h1><img src="red.gif"/></h1> > > etc... > > can anyone me? > > Thanks!! preg_match('|<h1.*?>(.*?)</h1>|',$b,$matches); |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Paul Lautman ha scritto:
> nintesa wrote: >> Hello... I'm trying to write a regular expression to match the content >> of a html tag. >> >> I need to match the content of <h1> i.e. >> >> <h1>Hello World</h1> >> <h1 class="red_background">Hello World</h1> >> <h1><img src="red.gif"/></h1> >> >> etc... >> >> can anyone me? >> >> Thanks!! > > preg_match('|<h1.*?>(.*?)</h1>|',$b,$matches); > > Are all working... but I can't make it work with tag <a>... |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
..oO(nintesa)
>Are all working... but I can't make it work with tag <a>... Same thing, if you just want the content of it. Or what's the problem now? Some more details, please. Micha |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Michael Fesser ha scritto:
> .oO(nintesa) > >> Are all working... but I can't make it work with tag <a>... > > Same thing, if you just want the content of it. Or what's the problem > now? Some more details, please. > > Micha ok... I have a page content in with I have some links like... <a href="mypage.php" class="test" alt="good" title="good title">Boing</a> I'm trying to get out: mypage.php (and similar) test (and similar) good good title Boing etc... Thanks for your ! |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
..oO(nintesa)
>I have a page content in with I have some links like... > ><a href="mypage.php" class="test" alt="good" title="good title">Boing</a> > >I'm trying to get out: > >mypage.php (and similar) >test (and similar) >good >good title > >Boing > >etc... That's a bit beyond the scope of regular expressions. It would be easier to use an HTML parser to turn the page into a DOM tree, where you can use XPath to access any arbitrary node (elements, attributes, values). Have a look at the DOM extension, especially DOMDocument->loadHTML() to begin with. See the manual for details and examples. Micha |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
nintesa wrote:
> Michael Fesser ha scritto: >> .oO(nintesa) >> >>> Are all working... but I can't make it work with tag <a>... >> >> Same thing, if you just want the content of it. Or what's the problem >> now? Some more details, please. >> >> Micha > > ok... > > I have a page content in with I have some links like... > > <a href="mypage.php" class="test" alt="good" title="good > title">Boing</a> > I'm trying to get out: > > mypage.php (and similar) > test (and similar) > good > good title > > Boing > > etc... > > Thanks for your ! Someone did something similar in this thread: http://groups.google.co.uk/group/com...1a97c30642065d |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
> Someone did something similar in this thread: > http://groups.google.co.uk/group/com...1a97c30642065d > > This seems to work: |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
nintesa ha scritto:
> >> Someone did something similar in this thread: >> http://groups.google.co.uk/group/com...1a97c30642065d >> >> > > This seems to work: > function tag_param_content($content,$tag,$param) { if ($tag!='img') { preg_match_all('|<'.$tag.'.*?.$param.'=["\'](.*?)["\'].*?>.*?</'.$tag.'>|',$content,$match); } else { preg_match_all('|<'.$tag.'.*?'.$param.'=["\'](.*?)["\'].*?>|',$content,$match); } return $match[1]; } |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
On Apr 27, 12:38am, nintesa <nint...@nomaaaaail.it> wrote:
> Hello... I'm trying to write a regular expression to match the content > of a html tag. > > I need to match the content of <h1> i.e. > > <h1>Hello World</h1> > <h1 class="red_background">Hello World</h1> > <h1><img src="red.gif"/></h1> > > etc... > > can anyone me? > > Thanks!! $pattern = "/<h1.*?>(.*)<\/h1>/"; test it. |
|
![]() |
| Outils de la discussion | |
|
|