note 110295 deleted from function.strpos by googleguy
| From: | googleguy@php.net | Date: | Tue, 09 Oct 2012 01:28:43 +0000 |
| Subject: | note 110295 deleted from function.strpos by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191194@lists.php.net to get a copy of this message | ||
Note Submitter: kamba jeno
----
Howto slice a string with strpos?
The following example shows how to get a substring url from a string.
<?php
function pictureurl($string){
$first = strpos($string,"src=");
$last = strpos($string,".jpg");
if(!is_numeric($last)){
$last = strpos($string,".JPG");
}
if(!is_numeric($last)){
$last = strpos($string,".png");
}
$url="";
for($i=$first+4;$i<=$last+4;$i++){
$url.=$string[$i];
}
return $url;
}