|
<?php
//作用: 一段字符串中读取图片地址
//注意: 我用的是单引号分割
/* example:
$test = new picurl_from_db;
$test->from_str = "奥运加油 <img src=' uploadfile/aoyfffffun.jpg' > 赢在中国";
$test->str1 = "<img src='";
$test->str2 = "\'";
$test->picurl();
*/
class picurl_from_db
{
var $from_str; //模拟存在数据库中的字符串 包含图片
var $str1; //前分隔符
var $str2; //后分割符
//private $final_str;
function picurl()
{
$pos_str1 = strpos($this->from_str, $this->str1) + strlen($this->str1);
for($pos_str1; ; $pos_str1++)
{
$c = substr($this->from_str, $pos_str1, 1);
if(@$c == '\'') //看这个地方是 src= 用的是 ' " 还是什么也没有
break;
@ $final_str .= $c;
}
echo $final_str;
}
}
/*$test = new picurl_from_db;
$test->from_str = "奥运加油 <img src=' uploadfile/aoyfffffun.jpg' > 赢在中国";
$test->str1 = "<img src='";
$test->str2 = "\'";
$test->picurl(); //打印结果*/
?> |
|