比如我有一個img標籤這樣的...在保存到數據庫之前,用特定的類替換所有的img標籤?
<img alt="INLINE:143246;w=240;h=240" class="wysiwyg-inline-image" src="/sites/default/files/styles/inline_image_temp_240x240/public/2013/05/30/600x600_30.png?itok=7mP9F2QH" />
我希望它由...
<p><!-- INLINE:143220;w=240;h=240 --></p>
保存到數據庫基於img
alt屬性之前替換。
注意:圖片的數量是動態的,因此用戶可能會上傳多張不同尺寸的圖片。圖像尺寸在圖像上。
到目前爲止,我有這樣的代碼。
preg_match_all("/(<img[^>]+>)/i", $node->body[LANGUAGE_NONE][0]['value'], $matches);
foreach($matches as $match) {
// Replace all matched elements here.
}
哪裏的了'$ 1'來自?它是否將'$ str'視爲數組,並且alt處於位置1? – ninjascorner
$ 1將包含模式的第一個匹配的字符串。是的,在這種情況下它將包含alt值。 – Jithin
你不需要'preg_match_all'並做循環,你只需要用'preg_replace'替換代碼 – Jithin