如何正确使用urlencode

时间:2015-09-18 10:16:28

标签: php html cmsmadesimple

我想通过添加php生成的div的内容来构建一个url。 到目前为止,网址看起来像这样:

echo '<a class="itemBook fancybox fancybox.iframe"; $url =  href="/contactforms/inspection.php?inspection=true&src=">Group Enquiry</a>';

在src =之后我需要添加此行生成的内容:

echo '<h3>' . $item['title'] . '<br />' . $item['location'] . '</h3>';

非常感谢任何想法:)

1 个答案:

答案 0 :(得分:0)

永远不要混用HTML和PHP!

在PHP中构建您的URL

<?php
    // building url 
    ...
    $url =  "/contactforms/inspection.php?inspection=true&src=" ;
    // send it to your front-end : i assume that an Ajax is waiting for your response
?>

文件已分开

<html>
    <script>
        // once you received your URL from your back-end
        var url = // value from PHP; 
        document.getElementById('linkContainer').innerHTML = "<a href='" + url + "'>My Link</a>";
    </script>
<body>
    <div id="linkContainer"></div>
</body>
</html>