我如何将这两个preg_replace一起添加?我迷失了怎么做。
<?= preg_replace('/@(\w+)/', '<a href="https://www.twitter.com/$1">@$1</a>', stripslashes($row['tweet_text']))?>
<?= preg_replace('/#(\w+)/', '<a href="https://twitter.com/#!/search/$#$1">#$1</a>', stripslashes($row['tweet_text']))?>
它会为
做这两件事stripslashes($row['tweet_text']
答案 0 :(得分:3)
你可以这样做:
$regex = array('/@(\w+)/','/#(\w+)/');
$replace = array(
'<a href="https://www.twitter.com/$1">@$1</a>',
'<a href="https://twitter.com/#!/search/$#$1">#$1</a>'
);
preg_replace($regex,$replace,stripslashes($row['tweet_text']));