douquqiang1513 2015-11-05 08:46
浏览 31
已采纳

从textarea获取包含PHP链接的每一行

This question solved my problem only until getting each line from textarea. But when I access the link (what contains in each line) with simplexml_load_file to get the data, the link started to end with unique codes:

foreach ($textAr as $line) {
    echo $line = trim($line)."<br/>"; //I trim it again just to make sure, and the result is the right link.
    echo $xml = simplexml_load_file($line)."<br/>"; //code like %3Cbr/%3E showed up at the end of the link
}

And the error is something like:

A PHP Error was encountered

Severity: Warning

Message: simplexml_load_file(link%3Cbr/%3E) [function.simplexml-load-file]: failed to open stream: HTTP request failed!

I replace the real link with link on the error message.

How to remove the unique codes (%3Cbr/%3E)? I've tried str_replace("%3Cbr/%3E","",$line) but it's not working.

  • 写回答

1条回答 默认 最新

  • doubeng9567 2015-11-05 08:49
    关注

    It is just a matter of removing .<br/>

    echo $line = trim($line);
    

    The %3Cbr/%3E represents the <br/>

    The reason why str_replace("%3Cbr/%3E","",$line) doesn't work, is because the line does not contain %3Cbr/%3E. It contains <br/>. Only if the link tries to open it, it will encode the url, replacing the < and > signs, which makes it 3Cbr/%3E.

    I'm not sure if you mean to also print all the lines, but if you don't, you can remove the echo.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改