2011-07-27 32 views
3

このコードは構文エラーを起こしています。誰が問題がどこにあるのか教えていただけますか?前もって感謝します。PHPコードのヘルプ

echo "<div class='cvtitle'><div><a class="bloc_ca" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html"><b>".html_entity_decode(substr($video['video_title'],0,100))."..</b></a></div><div class='cvdisc'><span style='word-break:wrap'>".html_entity_decode(substr($video['video_desc'],0,100))."</span></div><div class='cvviews'> View Count: <b>".$video['views']."</b></div></div></div>"; 
+0

余分なものを含んでいるようだし、あなたの質問は...? –

+0

ご迷惑をおかけしておりますが、このコードのどこに問題がありますか?ありがとう – maxlk

+0

それはエスケープ問題です。私の答えを読む、私はあなたのためにそれを修正し、何が間違っているか教えてくれた。 – Chris

答えて

3

あなたは脱出しなければなりません。代わりに:

echo 'some text' . "aaaa"aaaa"; 

書き込み:

echo "<div class='cvtitle'><div><a class=\"bloc_ca\" href=\"" . $video['video_id'] 
. '_' . str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)) 
. '.html"><b>' 
. html_entity_decode(substr($video['video_title'],0,100)) 
. "..</b></a></div><div class='cvdisc'><span style='word-break:wrap'>" 
. html_entity_decode(substr($video['video_desc'], 0, 100)) 
. '</span></div><div class="cvviews"> View Count: <b>' 
. $video['views'] 
. '</b></div></div></div>'; 

P.S.:

echo 'some text' . "aaaa\"aaaa"; 
はこのような何かにあなたの例を書き換え

コードは読みにくいです。 1つのタイプの引用符を使用して文字列を囲み、その文字列の中で別の文字列を安全に使うことができます。また

- 覚えている - あなたは "中"またはあなたの文字列をラップしている場合 - あなたはそれの前にバックスラッシュを追加することで、文字列の内部でこの文字をエスケープする必要があります。

あり

http://php.net/manual/en/language.types.string.php

+1

ありがとうございます。わかった。 – maxlk

0

私はこのコードを取得しています:

echo " 
".html_entity_decode(substr($video['video_title'],0,100)).".. 
".html_entity_decode(substr($video['video_desc'],0,100))." 
View Count: ".$video['views']." 
"; 
2
echo '<div class=\'cvtitle\'><div><a class="bloc_ca" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html"><b>"'.html_entity_decode(substr($video['video_title'],0,100))."..</b></a></div><div class='cvdisc'><span style='word-break:wrap'>".html_entity_decode(substr($video['video_desc'],0,100))."</span></div><div class='cvviews'> View Count: <b>".$video['views']."</b></div></div></div>"; 

\あなたはいくつかの逃げ出した問題を抱えていました。あなたはいくつかの文字列を 'と一緒に終わらせていましたか'、または逃げずに間違って閉じてしまったのですか?

+0

ありがとうございます – maxlk

1

二重引用符と一重引用符を混ぜて、 e文字。 あなたが返す文字列も</div>

echo '<div class="cvtitle"> 
    <div> 
     <a class="bloc_ca" href="'. $video['video_id'] . '_' . str_replace(' ','-',substr(html_entity_decode($video['video_title']),0,20)) . '.html"> 
      <b>' . html_entity_decode(substr($video['video_title'],0,100)) . "..</b></a> 
    </div> 
    <div class='cvdisc'> 
     <span style='word-break:wrap'>" . html_entity_decode(substr($video['video_desc'],0,100))."</span> 
    </div> 
    <div class='cvviews'> 
     View Count: <b>".$video['views']."</b> 
    </div> 
    </div>";