Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我只想从href语句中获取URL_Php_Wordpress - Fatal编程技术网

Php 我只想从href语句中获取URL

Php 我只想从href语句中获取URL,php,wordpress,Php,Wordpress,我只想从一个 我试过一种方法,但当我将代码放入实际的wordpress页面时,它可以处理简单的文件,它给出了一个错误 <?php $string = "this is my friend's website <a href=http://facebook.com/baberzaman > I think it is coll</a>"; $url = explode(' ',strstr($string,'http://'))[0]; ?> <br>

我只想从一个 我试过一种方法,但当我将代码放入实际的wordpress页面时,它可以处理简单的文件,它给出了一个错误

<?php
$string = "this is my friend's website <a href=http://facebook.com/baberzaman > I think it is coll</a>";
$url = explode(' ',strstr($string,'http://'))[0];
?>
<br><br>
<?php echo $url; 
?>
我希望很快得到帮助

谢谢

function()[index] 
仅在php5之后可用。查看您的php版本。 你还是可以的

$urlarray = explode(' ',strstr($string,'http://'));
$url = $urlarray[0];

我认为在当前版本的php中,数组解引用是不可能的

你的php版本应该在5.4以上。查看详细说明

欲了解更多信息,请查看

所以,如果您不想更新到最新版本,可以这样使用

$url = explode(' ',strstr($string,'http://'));
echo $url[0];
如果您的字符串没有http://则可以使用此正则表达式提取href的值

$pattern = '~\bhref\s*+=\s*+["\']?+\K(?!#)[^\s"\'>]++~';
preg_match_all($pattern, $string, $out);
echo $out[0];

phpI的版本是什么?我觉得这很有趣,而且几乎是同时出现的。因为这家伙真的可以使用这个模块的php版本:PYour这段代码很有效。但有一个问题。。带有URL的字符串出现了(Thing),它给了我out put(),但我只想要out put链接。(). 这是额外的“>好现在请帮我解决这个@PeterSmith@peter你的这段代码是有效的。但其中有一个问题..带有URL的字符串出现了(),它给了我输出(progsofts.com/remilamande/photo/good picture/“>good),但我只想要输出链接。(progsofts.com/remilamande/photo/good picture)。这是额外的“>好现在请帮我解决这个。。
$pattern = '~\bhref\s*+=\s*+["\']?+\K(?!#)[^\s"\'>]++~';
preg_match_all($pattern, $string, $out);
echo $out[0];