我的页面包含很多锚,我必须将该html放入wiki页面。如何在php中将锚转换为wiki url?
示例:<a href="http://www.php.net/manual/en/memcached.add.php">add </a>
将是[http://www.php.net/manual/en/memcached.add.php add]
我认为这应该有效:
<?php
echo $output = preg_replace("/<a's+href's*='s*[''"]?(.+)[''"]?'s*>(.+)<'/a>/",
"[$1 $2]",
"<a href=http://www.php.net/manual/en/memcached.add.php>add </a>");
?>
怎么样:
echo preg_replace('#<a.+href="(.+?)".*?>'s*(.+?)'s*</a>#', "[$1 $2]",
'<a href="http://www.php.net/manual/en/memcached.add.php">add </a>');
输出:
[http://www.php.net/manual/en/memcached.add.php add]