php 正则字符串替换字符串,PHP用正则表达式替换字符串(Php replace string with regex)...

PHP用正则表达式替换字符串(Php replace string with regex)

我想用“”替换我的文件中的所有标签“<_tag_>”。

我试过这个解决方案:

$_text = preg_replace('', '', $_text);

但我用“<>”替换“<_tag_>”

$_text = preg_replace('', '', $_text);

但我用“<>”替换“<_tag_>”

我怎样才能选择尖括号?

I want replace in my file all tags "<_tag_>" with "".

I've tried this solutions:

$_text = preg_replace('', '', $_text);

But I replace "<_tag_>" with "<>"

$_text = preg_replace('', '', $_text);

But I replace "<_tag_>" with "<>"

How can I also select angle brackets?

原文:https://stackoverflow.com/questions/47681461

2020-03-03 05:15

满意答案

它可能是

# <_ anything lazily afterwards followed by _>

在PHP :

$string = preg_replace('~<_.>~', '', $string);

如在

$string = "some <_tag_> here";

$string = preg_replace('~<_.>~', '', $string);

echo $string;

# some here

?>

It could be

# <_ anything lazily afterwards followed by _>

In PHP:

$string = preg_replace('~<_.>~', '', $string);

As in

$string = "some <_tag_> here";

$string = preg_replace('~<_.>~', '', $string);

echo $string;

# some here

?>

2017-12-06

相关问答

这样做: $string = '[quote name="username" url="/t/44223/topics-name#post_734738"]';

$new = "";

if(preg_match("/\[quote name=\"([^\"]*)\" url=\"\/t\/[^#]*#post_([0-9]*)\"\]/",$string,$reg)) {

$new = "[quote=".$reg[1].";new post number based on ".$reg[...

描述 我会通过首先将字符串拆分为带引号或不带引号的字符串组来解决此问题。 然后迭代匹配,如果填充了Capture Group 1,则引用该字符串,以便在替换Capture Group 0时进行简单替换。如果未填充Capture group 1,则跳到下一个匹配。 在每次迭代中,您只想构建一个新字符串。 由于拆分字符串是困难的部分,我会使用这个正则表达式: ("[^"]*")|[^"]* 例 示例文本 "mission podcast" modcast A B C "D E F"

码 PHP Co...

以下是解决此问题的正则表达式变体: <?php

$theData = "image.png%5C%22";

$src = "/image.png";

$width = 10;

//you must escape potential special characters in $src,

//before using it in regexp

$regexp_src = preg_quote($src, "/");

$theData = preg_...

怎么样: $str = '...||date|14.02.2010||interest|games and books||options|opt1, opt2 and opt3||age|24||...';

$str = preg_replace('/(\|options\|[^|]*) and/', "$1,", $str);

echo $str,"\n";

输出: ...||date|14.02.2010||interest|games and books||options|opt1, o...

如果您知道您的字符串将始终以“我的商店名称 - 标记 - ”开头,那么您可以通过preg_replace()函数使用以下内容: $input = preg_replace("^My Store Name - Tag - ", "", $input);

表达式本身只是使用^字符来表示字符串的开头,然后是你想要去掉的值。 If you know that your string will always begin with "My Store Name - Tag - ", then you can...

你写的正则表达式遍布整个地方。 让我们来看看这个模式: 无论发生什么,它都将从或/> (需要考虑那些讨厌的不尊重标准的网络海盗)。 你正在寻找rel参数,如果它有一个,它需要是规范的。 我们可以开始编写正则表达式: #]+)(/>|>)#is 。 这将映射所有link标记。 然后,您可以使用简单的strpos调用来解析参数。 如果您确定rel =“canonical”将是链接标记的第一个参数,您可以将正则表达式进一步扩展为#

它可能是 <_.>

# <_ anything lazily afterwards followed by _>

在PHP : $string = preg_replace('~<_.>~', '', $string);

如在 <?php

$string = "some <_tag_> here";

$string = preg_replace('~<_.>~', '', $string);

echo $string;

# some here

?>

在ideone.c...

你可以使用这个正则表达式进行搜索: (?<=\h|^)(?:[^\h\d]*\d){6}\S*

并用[removed]替换。 分手: (?<=\h|^) # loookbehind to assert previous position is line start or whitespace

(?: # start of non capturing group

[^\h\d]*\d # 0 or more non-space and non-digits ...

无论它的$或& (与您的问题混淆),请使用preg_replace()进行正则表达式替换。 $link = preg_replace("/[&$]option=(?:100|[0-9]|[1-9][0-9])\b/"," ",$actual_link);

我不认为你需要那个^来锚定! Whatever its $ or & (confused by your question), use preg_replace() for your regex replace. $link = preg_re...

PHP中的制表符(与许多其他语言一样)的转义序列是\t 。 试试这个: $find = array("\t");

$replace = array(' ');

$string = str_replace($find,$replace,$string);

The escape sequence for a tab character in PHP (as it is in many other languages) is \t. Try this: $find = array("\t");

$re...

相关文章

正则表达式定义了字符串的模式。 正则表达式可以用来搜索、编辑或处理文本。 正则表达式并不仅限于某一种语

...

匹配的模式(Pattern flags) compile( )方法还有一个版本,它需要一个控制正则表达

...

Java String类 字符串广泛应用在Java编程中,在Java中字符串属于对象,Java提

...

羡慕的代码我测试过了,问题出在\\s-\\s-\\s上,但是不知道为什么错啦....求指教! pri

...

哪位朋友帮忙看一下.这个正则表达式: String regex = "mailto:\\w

...

在regex包中,包括了两个类,Pattern(模式类)和Matcher(匹配器类)。Pattern类

...

第二点是,在本地号码位的前三位和后四位数字间有可能是空格符,而不是连字号,更有胜者,或根本就没有分隔符

...

【字符串与数组】 Q:Write a method to replace all spaces in

...

正则表达式(regular expression)就是用一个“字符串”来描述一个特征,然后去验证另一个

...

今天遇见一个问题.不知道怎么解决. 如: 自己建立了一个文件read.txt 里面存放这样的 键值

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值