简单的 preg_replace
我根本无法弄清楚 preg_replace,它对我来说看起来只是中文,无论如何我只需要从字符串中删除“&page-X
”(如果存在)。
X
当然是一个数字,如果有人有一个对初学者有用的 preg_replace
教程的链接,那也会很方便!
I cant figure out preg_replace at all, it just looks chinese to me, anyway I just need to remove "&page-X
" from a string if its there.
X
being a number of course, if anyone has a link to a useful preg_replace
tutorial for beginners that would also be handy!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实际上,正则表达式的基本语法(由
preg_replace
和朋友支持)非常容易学习。将其视为描述某种模式的字符串,其中某些字符具有特殊含义。在非常简单的情况下,可能的模式是:
\d
表示数字(数字字符 0-9),+
表示:重复之前的表达式+
(此处:\d
)一次或多次。所有其他角色仅代表他们自己。因此,上面的模式匹配以下任何字符串:
由于
preg
函数使用 Perl 兼容的语法,并且正则表达式在 Perl 中用斜线 (/
) 表示,因此您可以必须用斜杠包围模式:实际上,您也可以使用其他字符:
有关受支持语法的完整参考,请参阅 PHP 手册。
Actually the basic syntax for regular expressions, as supported by
preg_replace
and friends, is pretty easy to learn. Think of it as a string describing a pattern with certain characters having special meaning.In your very simple case, a possible pattern is:
With
\d
meaning a digit (numeric characters 0-9) and+
meaning: Repeat the expression right before+
(here:\d
) one or more times. All other characters just represent themselves.Therefore, the pattern above matches any of the following strings:
Since the
preg
functions use a Perl-compatible syntax and regular expressions are denoted between slashes (/
) in Perl, you have to surround the pattern in slashes:Actually, you can use other characters as well:
For a full reference of supported syntax, see the PHP manual.
preg_replace
使用 Perl 兼容的正则表达式 用于搜索模式。尝试此模式:有关详细信息,请参阅模式语法 。
preg_replace
uses Perl-Compatible Regular Expression for the search pattern. Try this pattern:See the pattern syntax for more information.
preg_replace()
preg_replace()
有用信息:
在 PHP 中使用正则表达式
http://articles.sitepoint.com/article/regular-expressions-php
Useful information:
Using Regular Expressions with PHP
http://articles.sitepoint.com/article/regular-expressions-php