dreljie602951 2014-08-22 12:02
浏览 15

根据Div元素拆分String

I have a string variable in PHP which is like

<html>
 <body>
   <div style="height: 10px; line-height: 10px;">
   </div>
 </body>
</html>

I want to split that String into two pieces

String 1

<html>
 <body>
   <div style="height: 10px; line-height: 10px;">

String 2

 </div>
 </body>
</html>

And then will insert some content into that DIV.

Note: Above string is just a sample to explain what I want, I have an HTML markup of 1000+ lines

As someone asked "What is your effort in PHP towards the query??"

$pieces = split('<div style="height: 10px; line-height: 10px;">', $template); 

But it contains the whole markup not the splited one

  • 写回答

2条回答 默认 最新

  • donglei1699 2014-08-22 12:08
    关注

    Well you could have your variable like

    <html>
     <body>
       <div style="height: 10px; line-height: 10px;">
       xyz123
       </div>
     </body>
    </html>
    

    And then use php explode function like

    $result = explode( 'xyz123', $yourvar );
    

    then access the two parts like

    $result[0] and $result[1]
    

    Note: xyz123 is used as a unique string for demo purpose.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度