What's the easiest way to grab a 6-character id from a string?
The id will always be after www.twitpic.com/ and will always be 6 characters.
e.g., $string = 'The url is http://www.twitpic.com/f1462i. Enjoy.';
$id = 'f1462i';
Thanks.
What's the easiest way to grab a 6-character id from a string?
The id will always be after www.twitpic.com/ and will always be 6 characters.
e.g., $string = 'The url is http://www.twitpic.com/f1462i. Enjoy.';
$id = 'f1462i';
Thanks.
preg_match("@twitpic\.com/(\w{6})@", "The url is http://www.twitpic.com/f1462i. Enjoy.", $m);
$id = $m[1];
Here you go. Complete working code without regex
:
<?php
$string = 'The url is http://www.twitpic.com/f1462i. Enjoy.';
$id = substr($string, strpos($string, 'http://www.twitpic.com/')+23, 6);
echo $id; //output: f1462i
?>
You could set it a get
// url = http://www.webaddress.com/id=12351 $id
$id = $_GET['id'];
Unless its from a variable http://php.net/manual/en/function.substr.php
$string = "http://www.twitpic.com/f1462i" ;
$id = substr($string,strpos($string, 'twitpic.com')+strlen('twitpic.com')+1,6) ;
echo $id ;