doutu3352 2012-09-09 08:24
浏览 39
已采纳

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

I am trying to add a few things mentioned below on my php code, but its throwing a parse error, when i try to open with firefox or any other browser for thar matter...hence would like some expertize on this one...

<?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条回答 默认 最新

  • doushouj966020 2012-09-09 08:25
    关注

    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";
    

    Or even simpler,

    $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";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题