PHP 从用户消息(字符串)中获取图像 url 不适用于 preg_match_all
PHP Get image url from user message (string) doesn't work with preg_match_all
你能告诉我我做错了什么吗?
它总是告诉我它是图像,即使它不是。
编辑:如果有图像 link,我需要获取图像的 link。
while ( $row = mysql_fetch_assoc( $result ) ){
$msg = "<div class='msg'>[" . $row["time"] . "] <b>" . $row["name"] . ":</b> " . $row["message"];
echo $msg;
preg_match_all( "/(https?:\/\/\S+\.(?:jpg|png|gif))\s+/", $msg, $urls );
if ( $urls ){
echo "ye, its image";
}
}
没有我想的那么难
while ( $row = mysql_fetch_assoc( $result ) ){
$msg = "<div class='msg'>[" . $row["time"] . "] <b>" . $row["name"] . ":</b> " . $row["message"];
echo $msg;
preg_match_all( "/(https?:\/\/\S+\.(?:jpg|png|gif))\s+/", $msg, $urls );
if ( $urls ){
echo '<img src=".$urls.">';
}
}
你能告诉我我做错了什么吗? 它总是告诉我它是图像,即使它不是。
编辑:如果有图像 link,我需要获取图像的 link。
while ( $row = mysql_fetch_assoc( $result ) ){
$msg = "<div class='msg'>[" . $row["time"] . "] <b>" . $row["name"] . ":</b> " . $row["message"];
echo $msg;
preg_match_all( "/(https?:\/\/\S+\.(?:jpg|png|gif))\s+/", $msg, $urls );
if ( $urls ){
echo "ye, its image";
}
}
没有我想的那么难
while ( $row = mysql_fetch_assoc( $result ) ){
$msg = "<div class='msg'>[" . $row["time"] . "] <b>" . $row["name"] . ":</b> " . $row["message"];
echo $msg;
preg_match_all( "/(https?:\/\/\S+\.(?:jpg|png|gif))\s+/", $msg, $urls );
if ( $urls ){
echo '<img src=".$urls.">';
}
}