Forum Moderators: coopster
http://www.example.com/viewVideo/Flags_/Playstation_3/FRACTURE_the_weapons/886086
The problem is flags maybe 2 or 5. I only need the numbers at the end of the url
This is what I have for the expression so far but it is not working
$muster= '#'.$urlex[0].'(?:www\.)?example.com/[^\/]+/(\d+)(?:[^"]+)?'.$urlex.'#'; [1][edited by: eelixduppy at 3:18 pm (utc) on Sep. 16, 2008]
[edit reason] exemplified [/edit]
This is an easy way to get the numbers from the end.
$urlBits = [url=http://uk.php.net/manual/en/function.explode.php]explode[/url]($url);
$last = [url=http://uk.php.net/manual/en/function.count.php]count[/url]($urlBits)-1;
$numbersAtTheEnd = $urlBits[$last];
If you need to use preg_match then you could use:
$pattern = '%^(?:http://)?(?:www\.)?example.com(?:\:80)?/(?:\w+/){4}(\d+)$%i';
if (preg_match($url, $pattern, $matches)) {
$numbersAtTheEnd = $matches[0]; // hopefully ;)
}
else {
echo 'Either the pattern is wrong or the url is...';
}
Welcome to Webmaster World :)
[edited by: PHP_Chimp at 4:49 pm (utc) on Sep. 16, 2008]
if (eregi("example.com", $link3))
{
$muster= '#'.$urlex[0].'example.com/([^\.]+)(?:[^"]+)?'.$urlex[1].'#';
$resultat= preg_match($muster, $link1, $matches);
$link2= '<object width="640" height="510"><param name="movie" value="http://example.com/'. $matches[2] . '"></param><param name="wmode" value="transparent"></param><embed src=http://example.com/' . $matches[2] . '/2 type="application/x-shockwave-flash" wmode="transparent" width="640" height="510"></embed></object>';
$link1=$link2;
$site=29;
}
$urlBits = explode('/',$url); Or even something like:
$num = substr(strrchr($url, '/'), 1);
Cast it if you need an actual number/integer.
A regular expression seems a bit overkill if this is what you require?
The regular expression that I posted will look through a fixed number of directories. So although it could be modified to look through an unknown number using a regex is overkill for what you want.
I would go with explode or substr methods, as these will probably be faster than a regex.
[edited by: PHP_Chimp at 9:28 am (utc) on Sep. 17, 2008]