Reply to Re: need help with a regs expression

Your name:

Reply:


Posted by romain.jouin on 09/14/05 20:27

EXPRESSION : $exp_reg ="[ ]*href[ ]*=[ ]*([^>]+)";


------------------------------------------------------
EXEMPLES:
------------------------------------------------------
CODE :
$exp_reg ="[ ]*href[ ]*=[ ]*([^>]+)";
unset ($reg);
ereg($exp_reg, '<a href = "./emp/coucou.html">', $reg);
print_r($reg);
echo "<br>";
unset ($reg);
ereg($exp_reg, '<a href= "./emp/coucou.html">', $reg);
print_r($reg);
echo "<br>";
unset ($reg);
ereg($exp_reg, '<a href ="./emp/coucou.html">', $reg);
print_r($reg);
echo "<br>";
unset ($reg);
ereg($exp_reg, '<a href="./emp/coucou.html">', $reg);
print_r($reg);
echo "<br>";
unset ($reg);
------------------------------------------------------
RESULT :
Array
(
[0] => href = "./emp/coucou.html"
[1] => "./emp/coucou.html"
)
<br>Array
(
[0] => href= "./emp/coucou.html"
[1] => "./emp/coucou.html"
)
<br>Array
(
[0] => href ="./emp/coucou.html"
[1] => "./emp/coucou.html"
)
<br>Array
(
[0] => href="./emp/coucou.html"
[1] => "./emp/coucou.html"
)




------------------------------------------------------
CODE :

$html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Index of /~romain/compack</TITLE>
</HEAD>
<BODY>
<H1>Index of /~romain/compack</H1>
<IMG SRC="/icons/folder.gif" ALT="[DIR]"> <A HREF = "EMP2/">EMP2/</A>
12-Sep-2005 11:41 -

<IMG SRC="/icons/unknown.gif" ALT="[ ]"> <A HREF
="EMP2/cargar_datos.php">cargar_datos.php</A> 13-Sep-2005 11:15
3k
<IMG SRC="/icons/unknown.gif" ALT="[ ]"> <A HREF=
"EMP1/concepto.php">concepto.php</A> 13-Sep-2005 10:46
12k
<IMG SRC="/icons/unknown.gif" ALT="[ ]"> <A HREF =
"conceptos.php">conceptos.php</A> 08-Sep-2005 10:44 3k';



preg_match_all("([ ]*href[ ]*=[ ]*([^>]+))", strtolower($html), $regs,
PREG_SET_ORDER);




print_r($regs);

------------------------------------------------------
RESULT :

Array
(
[0] => Array
(
[0] => href = "emp2/"
[1] => "emp2/"
)

[1] => Array
(
[0] => href ="emp2/cargar_datos.php"
[1] => "emp2/cargar_datos.php"
)

[2] => Array
(
[0] => href= "emp1/concepto.php"
[1] => "emp1/concepto.php"
)

[3] => Array
(
[0] => href = "conceptos.php"
[1] => "conceptos.php"
)

)

*******************************************************
hope it can help.
JR.
*******************************************************








Yannick Benoit a écrit :

> Hi!
> I use this to find all links in a page :
>
> [:space:]*(href)[:space:]*=[:space:]*([^ >]+)
>
> but recently i found out that it only works if links are setup this way: <a
> href = "...
>
> I would like to know if someone can help me find the proper expression which
> would work with <a href = "... <a href= "... <a href="... and <a href ="...
> its only a matter of spaces but i cant figure out how to make it work.
>
> Thank you

[Back to original 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

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