Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在字符串中包含php preg_replace_Php - Fatal编程技术网

在字符串中包含php preg_replace

在字符串中包含php preg_replace,php,Php,我试图在字符串中包含一个php函数,但语法错误。有人能帮忙吗 $string = "<div id=\"apostnav\"><span class=\"calcir b-" . $string=get_field('br_category'); $string=preg_replace("/[^a-zA-Z]/", "", $string); echo strtolower($string) . "></span></div>"; 试试这个:

我试图在字符串中包含一个php函数,但语法错误。有人能帮忙吗

$string = "<div id=\"apostnav\"><span class=\"calcir b-" . $string=get_field('br_category');
$string=preg_replace("/[^a-zA-Z]/", "", $string);
echo strtolower($string) . "></span></div>";
试试这个:

$string=get_field('br_category');
$string=preg_replace("/[^a-zA-Z]/", "", $string);

$string = "<div id=\"apostnav\"><span class=\"calcir b-" . strtolower($string) . "\"></span></div>";
试试这个:

$string=get_field('br_category');
$string=preg_replace("/[^a-zA-Z]/", "", $string);

$string = "<div id=\"apostnav\"><span class=\"calcir b-" . strtolower($string) . "\"></span></div>";
您可以使用too来打印带有变量的html字符串:

printf('<div id="apostnav"><span class="calcir b-%s"></span></div>', strtolower(preg_replace('/[^a-zA-Z]/', '', get_field('br_category'))));
您可以使用too来打印带有变量的html字符串:

printf('<div id="apostnav"><span class="calcir b-%s"></span></div>', strtolower(preg_replace('/[^a-zA-Z]/', '', get_field('br_category'))));

您不能在另一个变量定义中定义新变量。@user2342558,$string的值立即被覆盖,这是完全有效的PHP@Nick啊,我刚学到一些有趣的东西:thanks@user2342558我确实认为你的答案实际上是OP想要的,只是那句话不正确。你不能在另一个变量定义中定义一个新变量。@user2342558虽然没有意义,$string的值立即被覆盖,这是完全有效的PHP@Nick啊,我刚学到一些有趣的东西:thanks@user2342558我确实认为你的答案实际上是OP想要的,只是那句话是不正确的。