簡體   English   中英

顯示包含引號的php變量

[英]display a php variable that contain quotes

我有一個xml文件,我嘗試將一些信息顯示到php表單中。

所以我一直試圖做那樣的事情:

<?php 

$url="tmp/".$_GET['n_doss']."-".date('d-m-Y')."-legale.xml";
if(file_exists($url))
{

     $chaineXML= $url;
     $dom = new DomDocument();
     $dom->load($chaineXML);
     $date = $dom->getElementsByTagName('time');
     $time = DateTime::createFromFormat("d/m/Y H:i:s", $date->item(0)->nodeValue);
     $datecreditsafe=date_format($time, 'd-m-Y');
     if($dom->getElementsByTagName('errors')->length != 0)
     {
        header('Location: index.php?p=add_debiteur&n_doss='.$_GET['n_doss'].'&type='.$_GET['type'].'&mode='.$_GET['mode'].'&step=4&creditsafe=false&siret='.$_GET['siret'] );
     }
       else
      {
         if(!empty($data['forme_juridique']))
         {
              echo "<label>Forme juridique:</label><input type='text' name='forme_juridique'><br>";
         }
         else
         {
             if($dom->getElementsByTagName('legalform')->length != 0)
                 {
                 $etat = $dom->getElementsByTagName('legalform');
                 $forme_juridique=$etat->item(0)->nodeValue;    
                 echo "<label>Forme juridique:</label><input type='text' name='forme_juridique' value='".utf8_decode(stripslashes($forme_juridique))."'><br>";
                 }
                 else
                 {
                 echo'<label for="forme_juridique">Forme Juridique:</label><table width="45%"       border="0">
                        <tr>
                        <td width="50%"><input type="checkbox" name="forme_juridique" value="SAS" onclick="limite_check(this.name, 1)" />
                        SAS</td>
                        <td width="50%"><input type="checkbox" name="forme_juridique" value="SA" onclick="limite_check(this.name, 1)" />
                          SA</td>
                          </tr>
                          <tr>
                        <td><input type="checkbox" name="forme_juridique" value="SARL" onclick="limite_check(this.name, 1)" /> 
                        SARL</td>
                    <td><input type="checkbox" name="forme_juridique" value="EURL" onclick="limite_check(this.name, 1)" />
                      EURL</td>
                      </tr>
                      <tr>
                        <td><input type="checkbox" name="forme_juridique" value="SNC" onclick="limite_check(this.name, 1)" />
                    SNC</td>
                    <td><input type="checkbox" name="forme_juridique" value="SDF" onclick="limite_check(this.name, 1)" />
                  SDF</td>
                  </tr>
                  <tr>
                <td><input type="checkbox" name="forme_juridique" value="Soci&eacute;t&eacute;  Particuli&egrave;re" onclick="limite_check(this.name, 1)" />
                  Soci&eacute;t&eacute; Particuli&egrave;re </td>
                <td><input type="checkbox" name="forme_juridique" value="Entreprise Individuelle" onclick="limite_check(this.name, 1)" />
                  Entreprise Individuelle</td>
                  </tr>
                  <tr>
                <td><input type="checkbox" name="forme_juridique" value="Artisan" onclick="limite_check(this.name, 1)" />
                  Artisan</td>
                <td><input type="checkbox" name="forme_juridique" value="Commer&ccedil;ant"     onclick="limite_check(this.name, 1)" />
              Comme&ccedil;ant</td>
              </tr>
              <tr>
            <td><input type="checkbox" id="box" name="forme_juridique" value="Autre" onclick="GereControle(\'box\', \'forme_juridique2\', \'1\');limite_check(this.name, 1)"/>
              Autre</td>
            <td><input type="text" name="forme_juridique2" id="forme_juridique2" style="visibility:hidden" /></td>
              </tr>
        </table>';
                 }

            }
      }

但真正的麻煩在於,它只向我顯示了這個變量的一部分:實際上要顯示的真實部分是:SAàconseild'administration

它只顯示SAàconseild

我嘗試過幾樣的事情:

str_replace("'","&#039;",$str) 

要么

htmlentities($str, ENT_QUOTES, "UTF-8")

或者再次使用mysql_real_escape_string

或者addslashesstripslashes

但我沒有找到讓它發揮作用的方法。

提前感謝您的幫助

嘗試用這個替換echo線:

echo '<label>Forme juridique:</label><input type="text" name="forme_juridique" value="' . htmlspecialchars($data['forme_juridique']).'"><br>';

嘗試:

str_replace('"','\"',$str)

你檢查了它回復的實際HTML嗎? 因此,您可以知道它是由單引號問題引起的還是內容確實是“SAàconseild”。

或者您可以使用雙引號引用該值。

此代碼將提供更好的結果:

addslashes($data['forme_juridique'])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM