php
  • string
  • url
  • escaping
  • 2013-03-11 68 views 1 likes 
    1

    部分包括URL串的建設如下:如何在PHP字符串中有撇號?我<code>PHP</code>代碼

    $msg = $_REQUEST["msg"]; 
    $content = 'action=sendmsg'. 
           '&user='.rawurlencode($username). 
           '&password='.rawurlencode($password). 
           '&to='.rawurlencode($destination). 
           '&text='.rawurlencode($msg); 
    

    $msg恰好包含撇號,它被髮送爲"\'"

    我需要做些什麼來確保PHP沒有插入反斜槓?

    回答

    4

    你可能想看看的stripslashes:http://php.net/manual/en/function.stripslashes.php

    2

    假設你要發送的$content變量,而不是僅僅剝離反斜槓,考慮使用urlencode(),而不是rawurlencode()。另外,您可以爲您的$content變量使用一次該功能。

    $content = urlencode($content); 
    

    UPDATE:urlencoderawurlencode可能不適合你的情況。你爲什麼不發送沒有URL編碼的$content?你如何發送我們的查詢字符串?如果使用cURL,則不需要對參數進行編碼。

    +0

    'urlencode()'和'rawurlencode()'有什麼區別? – CJ7 2013-03-11 04:21:08

    +0

    檢查此:http://stackoverflow.com/questions/996139/php-urlencode-vs-rawurlencode – Raptor 2013-03-11 04:25:08

    +0

    更新答案。只是好奇你如何使用查詢字符串。 – Raptor 2013-03-11 04:27:02

    1

    您可以嘗試

    1. Stipslashes
    2. 或將字符串 「」,並添加「您希望。
    +0

    請解釋downvote的原因 – 2013-03-11 08:33:15

    相關問題