duanqiang2617 2017-05-23 09:46
浏览 106

如何在mysql中以html格式存储数据时在php中使用substring?

Text is stored in HTML format paragraph tags.

Field Name:descr

Stored data:

<html>
<head>
    <title></title>
</head>
<body>
<div class="campusInfoNamesake">
<p>If someone had said to me ten years ago that autism and the therapeutic benefits of gardening will become your life, I wouldn&rsquo;t have believed them.</p>

<p>Although it&rsquo;s still very early days, things are starting to take shape on my smallholding in Ceredigion, West Wales.</p>
</div>
</body>
</html>

Above structure only datas stored in table see mysql table image bellow:

enter image description here

I need to retrive only 100 string in the body tag.. I used this code: <?php echo substr($row01[descr], 100); ?> but i can't get the result when using this code. Please help me.

  • 写回答

2条回答 默认 最新

  • doupu2722 2017-05-23 09:53
    关注

    you need to use regex to retrieve everything between your <body>-Tags first, then you are able to cut the string you need.

    preg_match_all('/<body>(.*?)<\/body>/s', $row01['desc'], $matches);
    
    //HTML array in $matches[1]
    print_r(substr($matches[1],100));
    

    See regex here: PHP Regex find text between custom added HTML Tags

    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办