dongxiong4571 2012-10-19 17:00
浏览 29
已采纳

在PHP中使用$ _POST构造URL

I am creating a page where users can submit metadata about content to a database by submitting the Digital Object Identifier (DOI) of the content. The site will then go and look up the metadata of content on www.crossref.org and present a summary of the data before adding it to the database

I have created a form for users to enter the DOI

<FORM ACTION="newref-getxml.php" METHOD=POST>
<P><strong>New Reference Form</strong><BR>
DOI: <INPUT NAME="send_doi"><BR>
<BR>
<INPUT TYPE=SUBMIT NAME="submitref" VALUE="SUBMIT">
</FORM>

And a file to fetch and read the XML (I have removed my API KEY from the URL for obvious reasons)

<?php
  echo $_POST[send_doi]; // check post data is coming though
  $xml = simplexml_load_file("http://www.crossref.org/openurl/id=doi:'$_POST[send_doi]'&noredirect=true&pid=APIKEY&format=unixref");
?>
<p>
   Title: <?php echo $xml->doi_record->crossref->journal->journal_article->titles->title;?><br />
   Year: <?php echo $xml->doi_record->crossref->journal->journal_article->publication_date->year;?><br />
   Journal: <?php echo $xml->doi_record->crossref->journal->journal_metadata->full_title;?><br />
   DOI: <?php echo $xml->doi_record->crossref->journal->journal_article->doi_data->doi;?>
</p>

The problem is with inserting the user submitted DOI into the URL, I thought I could just paste '$_POST[send_doi]' into the URL where the DOI should go, but that is not working.

All I get is

10.3998/3336451.0009.101 Title: Year: Journal: DOI:

When submitting a DOI

How you write the URL to include the '$_POST[send_doi]' value?

  • 写回答

2条回答 默认 最新

  • duanlv1366 2012-10-19 17:07
    关注
    simplexml_load_file("http://www.crossref.org/openurl/id".
        "?doi=".urlencode($_POST[send_doi]).
        "&noredirect=true&pid=APIKEY&format=unixref");
    

    Added a question mark as I don't see it in your URL. A better alternative is http_build_query(). Check it out!

    simplexml_load_file('http://www.crossref.org/openurl/id?'. // <- Question Mark here
        http_build_query(array(
            'doi'       => $_POST[send_doi],
            'noredirect'    => 'true',
            'pid'       => 'APIKEY',
            'format'    => 'unixref',
        ))
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用