Jump to content

[SOLVED] how to grab certain word from url


pixeltrace

Recommended Posts

geek way.

<?php

$url="http://www.domainname.com/0903/filename.php?id=1";

if(preg_match_all("/[0-9]{4}/",$url,$matched)){

PRINT_R($matched);
}
?>

 

result

Array
(
    [0] => Array
        (
            [0] => 0903
        )

)

 

encase need the variable for anything.

<?php

$url="http://www.domainname.com/0903/filename.php?id=1";

if(preg_match_all("/[0-9]{4}/",$url,$matched)){

$result=$matched[0][0];
}

echo $result;
?>

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.