php帮助 - 需要使用字符串回显php

时间:2012-09-09 08:24:12

标签: php javascript

我正在尝试在我的php代码中添加下面提到的一些内容,但是当我尝试使用firefox或任何其他浏览器打开这个问题时,它会抛出一个解析错误...因此想要对这个问题有所了解...

<?php

$var1 = array();
//These are two of my website abc.com & abcdef.info...
$var1[] = "http://abc.com";
$var1[] = "http://abcdef.info";

$var2   = $var1[array_rand($var1)];

?>

//Now i need to echo $var2 on all 3 strings below, but as you see sometimes the echo needs to be executed not only by the end of the string but between the links of the below mentioned strings, so that i would be able to echo the final result from $test onto $var3.
<?php

$tests = array();
//three strings
$tests[] = "http://www.123.com/folder/subfolder.php?u="<?php echo "$var2";?>"";
$tests[] = "http://www.456.com?u="<?php echo "$var2";?>"&myimagelink&mydescription";
$tests[] = "http://www.some-other-site.com/okay/?u="<?php echo "$var2";?>"&myimagelink&mydescription";

$test   = $tests[array_rand($tests)];

?>

//an example of what needs to be printed according to a browser point of view is $var3 = http://www.456.com?u=http://abcdef.info&myimagelink&mydescription";
$var3 = "<?php echo "$var2";?>"

1 个答案:

答案 0 :(得分:2)

Concatenate

$tests[] = "http://www.123.com/folder/subfolder.php?u=".$var2;
$tests[] = "http://www.456.com?u=".$var2."&myimagelink&mydescription";
$tests[] = "http://www.some-other-site.com/okay/?u=".$var2."&myimagelink&mydescription";

甚至更简单,

$tests[] = "http://www.123.com/folder/subfolder.php?u=$var2";
$tests[] = "http://www.456.com?u=$var2&myimagelink&mydescription";
$tests[] = "http://www.some-other-site.com/okay/?u=$var2&myimagelink&mydescription";