PHP 用新行替换 [英] PHP Replace With New Line

查看:32
本文介绍了PHP 用新行替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 html 页面上我有这个.

<ol>

页面包含在名为 $content 的变量中.我想用其他东西替换它,但代码不起作用.

$content = str_replace("</h2><ol>", $title, $content);

我应该放什么而不是.

解决方案

而是使用 preg_replace 为此:

preg_replace("/<\/h2>[\s]*

    /", $title, $content);

不管你怎么做,它都没有真正的意义.<h2> 已启动,但是您删除了该结束标记和 <ol> 的开始标记,我假设它们也将具有结束标记?无论如何,您的输出似乎都会出错.

On a html page I have this.

</h2>
<ol>

The page is contained in a variable called $content. I want to replace this with something else but the code doesn't work.

$content = str_replace("</h2><ol>", $title, $content);

What should i put there instead of .

解决方案

Rather use preg_replace for this:

preg_replace("/<\/h2>[\s]*<ol>/", $title, $content);

Regardless of how you do it, it doesn't really make sense. An <h2> is started, but you remove that closing tag and the starting tag for the <ol>, which will also have a closing tag I assume? Seems like your output is going to be wrong regardless.

这篇关于PHP 用新行替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆