10/10/2018, 09:46
Cắt xâu kiểu gì để lấy được thế này
Bây giờ mình có 1 xâu như thế này
$a='<OBJECT type="application/x-oleobject" CLASSID="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" width="310" height="266" id="winMedia" name="winMedia"><param name="url" value="http://abc.com/abc/phim/loirumehien1.mp3"><param name="EnableContextMenu" value="0"><param name=volume VALUE=100><embed type="application/x-mplayer2" quality=high pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" file="http://abc.com/abc/phim/loirumehien1.mp3" src="http://abc.com/abc/phim/loirumehien1.mp3" WIDTH=310 HEIGHT=266 AutoStart="1" EnableContextMenu="1" Mute="0" ShowStatusBar="1" id="winMedia" name="winMedia"></OBJECT>';
Làm sao cắt trong cái đống lộn nhộn đó lấy được cái
$a = 'http://abc.com/abc/phim/loirumehien1.mp3';
Có nghĩa là lấy được cái link trong value hoặc trong src
Cảm ơn các bạn
[=========> Bổ sung bài viết <=========]
bổ xung, làm bằng php nhé
$a='<OBJECT type="application/x-oleobject" CLASSID="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" width="310" height="266" id="winMedia" name="winMedia"><param name="url" value="http://abc.com/abc/phim/loirumehien1.mp3"><param name="EnableContextMenu" value="0"><param name=volume VALUE=100><embed type="application/x-mplayer2" quality=high pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" file="http://abc.com/abc/phim/loirumehien1.mp3" src="http://abc.com/abc/phim/loirumehien1.mp3" WIDTH=310 HEIGHT=266 AutoStart="1" EnableContextMenu="1" Mute="0" ShowStatusBar="1" id="winMedia" name="winMedia"></OBJECT>';
Làm sao cắt trong cái đống lộn nhộn đó lấy được cái
$a = 'http://abc.com/abc/phim/loirumehien1.mp3';
Có nghĩa là lấy được cái link trong value hoặc trong src
Cảm ơn các bạn
[=========> Bổ sung bài viết <=========]
bổ xung, làm bằng php nhé
Bài liên quan
function scan($tmp)
{
$array = array();
do {
$pos = strpos($tmp, 'http://');
if($pos != false) {
$tmp = substr($tmp, $pos+7, strlen($tmp)- $pos + 1);
$url = ''; $i = 0;
while($tmp***91;$i***93; != '"' && $tmp***91;$i***93; != ' ' && $tmp***91;$i***93; != "'" && $tmp***91;$i***93; != ")" && $tmp***91;$i***93; != "***93;" && $tmp***91;$i***93; != "(" && $tmp***91;$i***93; != "***91;" && $tmp***91;$i***93; != ">" && $tmp***91;$i***93; != "<")
{
$url .= $tmp***91;$i***93;;
$i++;
}
$array***91;***93; = 'http://' . $url;
}
} while ($pos != false);
return $array;
}
Mình cắt chuỗi hoài mà nó chẳng ra..
Giúp mình với. Thanks bạn nhiều!
<?
$str = "<body><img src='pic1.jpg' width='200' height='100'/></body>";
$dom = new DOMDocument( '1.0', 'utf-8' );
$dom->loadXML( $str );
$elem = $dom->getElementsByTagName("img")->item(0);
//lấy thuộc tính bằng hàm getAttribute
$src = $elem->getAttribute("src"); // pic1.jpg;
$width = $elem->getAttribute("width"); // 200
$height = $elem->getAttribute("height"); // 100
?>
Cách luyện : vào trang chủ php.net mà luyện ha ,có ví dụ rất rõ ràng
<p>Test thử cái n<span style="color: blue;"><strong>ào Test thử cái nào T</strong></span>est thử cái nào Test thử cái nào<img src="images/stories/clock.jpg" border="0" /> Test thử cái nào Test thử cái nào</p>
Mà cắt chuỗi vẫn chưa lấy được để nó hiện ra cái hình
list($content, $img) = explode('<img', $html);
list($img, $content) = explode('/>', $img);
$img = '<img'.$img.'/>';
<?
$str = "<body><img src='pic1.jpg' width='200' height='100'/></body>";
$dom = new DOMDocument( '1.0', 'utf-8' );
$dom->loadXML( $str );
$elem = $dom->getElementsByTagName("img")->item(0);
//lấy thuộc tính bằng hàm getAttribute
$src = $elem->getAttribute("src") ;// pic1.jpg;
$width = $elem->getAttribute("width") ;// 200
$height = $elem->getAttribute("height") ;// 100
//lấy nguyên thẻ img nè
$img=$dom->saveXML( $elem );//<img src='pic1.jpg' width='200' height='100'/>
?>
bạn xem hình rồi giúp với nhé
cảm ơn bạn nhiều lắm!!!