如何在字符串中使用函数? [英] How to use a function inside string?
本文介绍了如何在字符串中使用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
'<a rel="nofollow" href="$1" class="bbc_link new_win" target="_blank">'
我想使用urlencode()
函数:
'<a rel="nofollow" href="urlencode($1)" class="bbc_link new_win" target="_blank">'
...但是我不能使用它:
... but I can't use this:
'<a rel="nofollow" href="'.urlencode($1).'" class="bbc_link new_win" target="_blank">'
...,因为$1
不是字符串中的变量;相反,它是一个简单的免费论坛中的元变量.
... because $1
is not a variable in the string; it is instead a meta-variable in a simple free forum.
它发送http://www.test.com/out.php?out=http://www.example.com
推荐答案
这个疯狂的黑客怎么样?
how about this crazy hack?
<?
$_ = 'urlencode';
echo "<a rel=\"nofollow\" href=\"{$_($1)}\" class=\"bbc_link new_win\" target=\"_blank\">";
这篇关于如何在字符串中使用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文