duandgfh0506 2014-03-18 00:45
浏览 20

PHP变量不适用于load函数

This works fine in when using echo/print:

<?php echo ('http://test.com/%%CENTER_NAME_LINK%%/feed/'); ?>

But when I use load, which I need, it does not add in the variable:

<?php
$rss = new DOMDocument();
$rss-> load ('http://test.com/%%CENTER_NAME_LINK%%/feed/');
$feed = array(); ...

Here's the setup:

$center_name_link = $center['center_name'];
$center_name_link = str_replace(' ', '-', $center_name_link);
$center_name_link = strtolower($center_name_link);
$html = str_replace('%%CENTER_NAME_LINK%%', $center_name_link, $html);

How can I get the load to work with the variable?! I've tried using ' . $center_name_link . ', but that does not show up in either echo/print or load. I've tried creating a variable with the link already in it. I've tried a lot of other things, but I just can't get it to work out...

  • 写回答

1条回答 默认 最新

  • doucheng3407 2014-03-18 01:13
    关注

    You need to use double quotes when you want to add a variable into a string eg

    <?php
    $rss = new DOMDocument();
    $rss->load ("http://test.com/$CENTER_NAME_LINK/feed/"); // NOTE $ sign
    $feed = array(); ..
    

    You can also add variables with the dot operate eg .

    $rss->load ("http://test.com/".$CENTER_NAME_LINK."/feed/"); // NOTE . between varialbe and text

    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python