2013-11-25 31 views
0

如何將allas文本添加到alt文本。問題是不需要的單引號。如何在兩個標籤之間添加?

文本 - > ALT =「照片OD從艾薩克·薩頓的收集額外的畫作拆封後」

應該是 - > ALT =「照片OD從艾薩克薩頓\額外畫作的收藏拆包」

<img width='318' height='238' alt='Photo od additional paintings from Isaac Sutton's  collection after unpacking' src='[!--$wcmUrl('resource','groups/public/documents/image/kppcont_083705.jpg')--]' title='Additional paintings from Isaac Sutton's collection after unpacking' /> 
+1

這不會幫助。 ''''不是HTML中的轉義字符。 – Quentin

回答

2

在alt標記周圍使用雙引號而不是單引號。

<img alt="Photo od additional paintings from Isaac Sutton's collection after unpacking" ... /> 
+0

奧卡姆的剃刀;) – CD001

2

「如何增加?」

通過使用addslashes()

$txt = "Photo od additional paintings from Isaac Sutton's collection after unpacking"; 
$txt = addslashes($txt); 

說了這麼多,即使有一個斜槓,這將不會在你的alttitle屬性起作用,因爲\不是HTML轉義字符。

你要麼需要在<img>標籤使用雙引號的屬性,或使用htmlentities()這樣的:

$txt = htmlentities($txt, ENT_QUOTES); 
1

你將有一個HTML屬性,使用它之前逃脫的價值。單引號之前的反斜槓將不起作用。在HTML/XML中,單引號作爲實體轉義。

如果您使用DOM來創建HTML,它將負責轉義。如果您將HTML創建爲文本,則htmlspecialchars()可以完成這項工作。

$text = "Additional paintings from Isaac Sutton's collection after unpacking"; 

var_dump(htmlspecialchars($text, ENT_QUOTES | ENT_HTML401)); 

輸出:

string(72) "Additional paintings from Isaac Sutton&#039;s collection after unpacking" 
0
<?php 
$alt=htmlentities("Photo od additional paintings from Isaac Sutton's collection after unpacking"); 
?> 
<img src="aamra24_ahmed_shafi1.jpg" width="473" height="347" alt="<?=$alt?>" /> 
<img width='318' height='238' alt='<?=$alt?>' src='[!--$wcmUrl('resource','groups/public/documents/image/kppcont_083705.jpg')--]' title='<?=$alt?>' /> 
相關問題