Home  >  Article  >  Backend Development  >  PHP截取html字符串有关问题

PHP截取html字符串有关问题

WBOY
WBOYOriginal
2016-06-13 10:46:13848browse

PHP截取html字符串问题
比如html里面是 “这是第一行
这是第二行
这是第三行” 这样的 我想截取出来以后 只显示 "这是第一样" 这样的 就是从
往后的全部不要了 第一行的内容长度不定 可以使截取第一行 也可以使删除
后面的 怎么方便怎么来 这个该怎么截取 请大牛们指教

------解决方案--------------------

PHP code
$arr=explode("<br>",$str);print_r($arr); Array(    [0] => 这是第一行    [1] => 这是第二行    [2] => 这是第三行)<br><font color="#e78608">------解决方案--------------------</font><br><span id="sp">这是第一行<br>这是第二行<br>这是第三行</span><br><script type="text/javascript"><br />var obj = document.getElementById('sp').innerHTML;<br />alert(obj.substr(0,obj.indexOf('\<')));<br /></script><div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn