2011-10-03 58 views
1

我已經有一段時間沒有使用PHP編碼,不記得如何做到這一點..內HTML中使用引號屬性

我使用的需要設置一些相對參數的jQuery插件。

$imgtag = '<a href="'.carturl($img->id,'images').'/'.$img->filename.'" class = "zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150"> 
<img src="'.$src.'"'.$titleattr.' alt="'.$alt.'" width="'.$width_a.'" height="'.$height_a.'" '.$classes.' /></a>'; 

現在我需要添加, position: "inside"到相對位,然而,每次我這樣做的時候,它在HTML輸出作爲引號所有的地方。該插件必須將「內部」這個單詞的引號零散地工作,但是,我需要在「rel =」引號內使用這些引號。

我該如何解決這個問題?

HTML輸出應該是這樣的:

<a style="position: relative; display: block;" href="http://www.URL.com/theimage.jpg" class="cloud-zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:"inside""> 
<img style="display: block;" src="http://www.URL.com/theimage.jpg" alt="product-picture" height="450" width="360"></a> 

謝謝!

+0

你確定應該有位置引號:「裏面」?不能只是位置:裏面? – itsmeee

+0

@itsmeee:它必須與引號:(不會工作沒有 – MartinH23

+0

它實際上是一個HTML問題,而不是PHP :) PHP只是生成任何HTML,你說他生成,所以我修正了標題更具描述性。 –

回答

0

試一下:

$imgtag = '<a href="'.carturl($img->id,'images').'/'.$img->filename.'" class = "zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:\'inside\' "> 
<img src="'.$src.'"'.$titleattr.' alt="'.$alt.'" width="'.$width_a.'" height="'.$height_a.'" '.$classes.' /></a>'; 
+0

完美!非常感謝。我會在5分鐘內接受這個答案;) – MartinH23

+0

謝謝 - 很高興它幫助你:) –

2

使用單引號

rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:'inside'" 

或反向

rel='adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:"inside"' 
+0

解析錯誤:語法錯誤,意外T_STRING – MartinH23

+0

發佈您的PHP代碼 - 這裏只是一個語法錯誤 – itsmeee

+2

@ MartinH23啊,它的所有內部php echo聲明? Ohwell,像'rel =「...,位置:\'在'\'」裏面。你必須轉義特殊字符 –

-1

您可以使用下面的語法轉義引號:

\"your stuff\" 

,這會使得包裹」,假設你也圍繞rel元素的外部引號

+1

嘗試此更早..輸出爲:position:\「inside \」「=」「> – MartinH23

+0

可能是因爲您的字符串用單引號括起來,以」和內部使用\「開頭以表示引號,例如be $ var =「」; – dougajmcdonald

+0

不可以,你不能通過在HTML中反斜槓來轉義字符,你可能會想到JavaScript或CSS。 –