根据用户输入自动替换部分字符串

时间:2011-10-08 16:15:44

标签: php

好的,在Python中,我可以有一个像

这样的网址
"(www.google.com/%s)" % cat

,输出为

"(www.google.com/cat)"

我如何在PHP中执行此操作?我不想回显输出,我想根据用户输入刮取给定的URL(即,他们放入股票代码,它将转到该股票代码的页面)

1 个答案:

答案 0 :(得分:1)

您正在寻找sprintf(或可能vsprintf,如果这样会更方便的话。)

$url = sprintf("(www.google.com/%s)", "cat");
echo $url;                                    // result: (www.google.com/cat)
相关问题