使用 PHP 查找并提取字符串


Find and Extracting a string using PHP

我正在开发一个小函数,用于从我的推特RSS提要中获取和显示项目。 但我以这种格式得到它:
标题 http://t.co/xxx

想要的是从我得到的字符串中提取 http://t.co/xx(URL)。所以我可以将其用作链接等。
感谢帮助:}

$item = "Title http://t.co/xxx";
preg_match( "/http'S+/", $item, $matches );
$url = $matches[0];

尝试:

$title = Title http://t.co/xxx
$final = str_replace("Title ","",$title);
$str = 'Title http://t.co/xxx';
echo substr($str, strpos($str, 'http'));

可能是学习正则表达式的好时机:)

试试这个

<?php
$s = '
Title http://t.co/xxx
Title http://t.co/yyy
';
$s2 = preg_replace( '@(Title |http://t.co/)@i', '', $s );
echo nl2br( $s2 );
?>