Jump to content

preg_match_all


Thomisback

Recommended Posts

Hi,

 

I have got a quick and simple question but I can't solve it.

I want to extract a number inside a link, e.g.:

<a href='/details.dx/sku.2695' style="text-decoration: none;">

I want to extract the number "2695" with preg_match_all although I have got no clue what to use, I tried:

 

    preg_match_all ("/a[\s]+[^>]*?href[\s]?=[\s\"\']+".

                    "(.*?)[\"\']+.*?>"."([^<]+|.*?)?<\/a>/",

                    $var, &$matches);

       

but that only works for normal links

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/115589-preg_match_all/
Share on other sites

<?php

$string="<a href='/details.dx/sku.2695' style=\"text-decoration: none;\">Blah Blah </a>";

preg_match_all("@<[^0-9]+([0-9]+)[^0-9]+>[^<]+<[^>]+>@", $string, $results);

echo "<pre>";

print_r($results);

echo "</pre>";

?>

 

Array

(

    [0] => Array

        (

            [0] => <a href='/details.dx/sku.2695' style="text-decoration: none;">Blah Blah </a>

        )

 

    [1] => Array

        (

            [0] => 2695

        )

 

)

Link to comment
https://forums.phpfreaks.com/topic/115589-preg_match_all/#findComment-594231
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.