我從數據庫中後臺打印出一些內容,其中一些內容可能具有圖像,但我只需要僅提取文本內容而不回顯任何可能的圖像內容。PHP:從正在回顯的內容中剝離圖像標籤
樣品:
$nws = '<h3>Just text Just text Just text Just text Just text Just text.</h3>
<p><img alt="" src="/opt_file/images/09062013C-pix1.jpg" style="width: 400px; height: 231px;" /></p>
<img alt="" src="/opt_file/images/another-pix2.png" style="width: 300px; height: 150px;" />
<p>Just text Just text Just text Just text Just text Just text.</p>
<p>Just text Just text Just text Just text Just text Just text.</p>
<p><strong>Sure these are just text.</strong></p>';
$nws = str_replace('<img alt="" src="" />', "" , $nws);
echo $nws;
我試着用str_replace函數撕掉內的任何圖像標籤或圖像,但它只是將無法正常工作。
此外,這些內容和圖像是動態的,並且有可能具有多個圖像。
真的需要解決這個問題,將非常感激得到幫助。
謝謝!
好極了!按照我需要的方式工作......感謝百萬... – John
很高興爲您提供幫助。請不要忘記通過點擊左側的複選標記來接受我的答案。 – Rikesh