Forum Moderators: coopster

Message Too Old, No Replies

Regular expression to catch links

         

romzinho2k7

5:07 am on Jul 29, 2007 (gmt 0)

10+ Year Member



Hey

I am with a problem in a script that I did.

I want to catch the links of a page html.

I did the whole page and i want to catch all that it is between href=""

Script that I did:
------------------------------
$page = "<html>
<head>
<title>Testing</title>
</head>

<body>
testing <a href='link--here' class='t'>link here</a> testing...testing <a href='link--here' class='t'>link here</a> testing...testing <a href='link--here' class='t'>link here</a> testing...testing <a href='link--here' class='t'>link here</a> testing...
</body>
</html>"

preg_match_all("¦<a href='(.*)' class='t'>]+>¦U", $page, $out);
print_r($out);
----------------------------------

It would like that the result was something as:
Link--here
Link--here
Link--here
...

Only that I do not am an expert in regular expression, and it is giving mistake in the line 18 - preg_match_all line

It would like to know they can help.

Sorry my english.

Psychopsia

5:18 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



Try this:

preg_match_all("#<a href='(.*?)' class='t'>.*?</a>#", $page, $out);

romzinho2k7

9:07 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



Error:

Parse error: syntax error, unexpected T_STRING in C:\www\test.php on line 18

In line preg_match_all.

Thanks

Psychopsia

5:00 am on Jul 31, 2007 (gmt 0)

10+ Year Member



Also ; is missing:

</body>
</html>"

preg_match_all

Should be:

</body>
</html>";