2011-07-27 2 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>'; 

추신 :

echo 'some text' . "aaaa\"aaaa"; 
이런 식으로 뭔가에 예를 다시 작성

코드는 읽기가 약간 어렵습니다. 하나의 따옴표를 사용하여 문자열을 감싸고 다른 문자열을 따옴표 안에서 안전하게 사용할 수 있습니다.

또한 - 기억 - 당신이 '나 문자열을 포장하는 경우 "- 당신은 문자열의 내부에이 문자를 탈출해야 그것의 앞에 백 슬래시를 추가하여 :이 \

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

큰 따옴표와 작은 따옴표를 혼합하여 탈출하는 고전적인 경우입니다 전자 문자. 당신이 반환 된 문자열은 또한 </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>";