Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

A problem with regular expression

Last post 10-05-2008, 10:08 AM by prometheuzz. 3 replies.
Sort Posts: Previous Next
  •  10-05-2008, 9:15 AM 46887

    A problem with regular expression

    Hi,

    I save html code in a variable :

    $text2=''<html><body>...<h4>URI : <a href="http://www.s.gr/CSS/screen/generic_13a.css">http://www.s.gr/CSS/screen/generic_13a.css</a></h4><table>...</body></html>";

    I want to match the line <h4>URI : <a href="http://www.s.gr/CSS/screen/generic_13a.css">http://www.s.gr/CSS/screen/generic_13a.css</a></h4>

     

    and then print :

    File Css : generic_13a.css

    File Path :  http://www.s.gr/CSS/screen/

     

    I am trying    preg_match_all('/<h4>URI : <[^>]*>[a-zA-Z:\/.]*<\/a><\/h4>/i',$text2,$match_css);

    but when I print it the output is the link , I would like to be only text.

     

    Thanks a lot

  •  10-05-2008, 9:33 AM 46888 in reply to 46887

    Re: A problem with regular expression

    You could do it like this:

    $text = '... your text ...';
    if(preg_match('/<h4>.*?\s+href="([^"]+\/)([^"]+)".*?<\/h4>/is', $text, $result)) {
      print_r($result);
    }

  •  10-05-2008, 9:48 AM 46889 in reply to 46888

    Re: A problem with regular expression

    Thank you very much!

    It is exact what I want!!

  •  10-05-2008, 10:08 AM 46890 in reply to 46889

    Re: A problem with regular expression

    Good to hear that, and you're welcome.
View as RSS news feed in XML