我有这个变量$img = $_POST['cur_image'];
其中cur_image的内容和$ img是:
<img style="display: inline;" src="http://news.bbcimg.co.uk/media/images/65348000/jpg/_65348094_belreuters.jpg" id="1" width="100"><img style="display: none;" src="http://news.bbcimg.co.uk/media/images/65356000/jpg/_65356067_65356066.jpg" id="2" width="100"><img style="display: none;" src="http://news.bbcimg.co.uk/media/images/65367000/jpg/_65367308_coffee.jpg" id="3" width="100"><img style="display: none;" src="http://news.bbcimg.co.uk/media/images/65376000/jpg/_65376729_heart.jpg" id="4" width="100">
所以我需要提取仅我获得的第一张图片的链接, (http://news.bbcimg.co.uk/media/images/65348000/jpg/_65348094_belreuters.jpg)
然后发送到db等
mysql_query("INSERT INTO `table` (img) VALUES ('$img')");
答案 0 :(得分:0)
这样的事情怎么样? (另)
$tmp_img = $_POST['cur_image'];
$img_path_offset = strpos($tmp_img, "src=") + 4;
$img_path_end = strpos($tmp_img, "\"", $img_path_offset);
$img = substr($tmp_img, $img_path_offset, $img_path_length);
然后运行你的MySql ..
干杯,Viggo
答案 1 :(得分:0)
使用preg_match可以执行以下操作:
$tmp_img = $_POST['cur_image'];
$match = "src=[\"'](.+?)[\"']"
preg_match($match, $tmp_img, $matches_array);
$img = substr($matches_array[0], 4, -1);
然后你的MySql ..