Home > Backend Development > PHP Tutorial > 请教 PHP 如何保留文本中的一段特定代码?

请教 PHP 如何保留文本中的一段特定代码?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:16:13
Original
1213 people have browsed it


@fdipzone

之前PHP里面的INPUT TEXT的问题非常感谢您

我现在可以用VB.NET完成一个修改HTML的功能,但是还是希望用PHP就可以完成,比较省事。

下面这部分VB代码,主要是把c:\vbt.htm打开,然后再掐头去尾,把txtmod之后和subContent之前的代码保留。再生成一个新的htm。

可以用PHP代码实现吗?请指点下。谢谢

        Dim a%, b%, s$, sok$        Dim HtmlFile As String        HtmlFile = "C:\vb.htm"        sok = ""        Web1.Navigate(HtmlFile)        For Each o In Web1.Document.GetElementsByTagName("div")            If InStr(o.innerHTML, "txtmod") > 0 Then                s = o.innerHTML                a = InStr(o.innerHTML, "txtmod")                b = InStr(o.innerHTML, "subContent")                sok = Mid(s, a - 1, b - a)                sok = Replace(sok, "=txtmod>", "")                sok = Replace(sok, "<SPAN class", "")                Exit For            End If        Next
Copy after login


回复讨论(解决方案)

$s = file_get_contents('t1.html');preg_match('/txtmod(.+?)subContent/is',$s,$m);file_put_contents('t2.html',$m[1]);
Copy after login

t1.html里面的内容是csdn论坛首页的内容,在里面加了 txtmod和 subContent,在导航栏的开头和结尾
t2.html里面是匹配到的导航栏

php 功能就是强大可能不用安装桌面软件来

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template