在设法使用 preg_match_all 之后,我想用matchedText替换匹配的文本,但它似乎不起作用。看看我的代码,我做错了什么?
<?php
$tweets = getTweets($profile->twitter_id);
for($i=0;$i<4;$i++):
// finds matches
$num_matches = preg_match_all('/@\w+/', $tweets[$i]->description, $matches);
if($num_matches):
echo $num_matches.'<br />';
for($c=0;$c<$num_matches;$c++):
$subject = $tweets[$i]->description;
$pattern = array();
$pattern[$c] = $matches[0][$c];
$replacement = array();
$replacement[$c] = '<a href="https://twitter.com/#!/">'.$matches[0][$c].'</a>';
endfor;
echo preg_replace($pattern, $replacement, $subject).'<br /><br />';
else:
echo auto_link($tweets[$i]->description).'<br /><br />';
endif;
endfor;
?>