Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: 范例 - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 范例

2025-04-26

范例

Example #1 正则表达式例子

<?php
// $string 中任意位置找到 "abc" 就返回 true。
ereg("abc"$string);            

// $string 中起始位置找到 "abc" 就返回 true。
ereg("^abc"$string);

// $string 末尾找到 "abc" 就返回 true。
ereg("abc$"$string);

// 客户浏览器是 Netscape 2、 3 或 MSIE 3 就返回 true。
eregi("(ozilla.[23]|MSIE.3)"$_SERVER["HTTP_USER_AGENT"]);

// 三个空格分割单词为 $regs[1]、 $regs[2]、 $regs[3]。
ereg("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+)"$string$regs); 

// $string 头部加一个 <br /> 标签。
$string ereg_replace("^""<br />"$string); 

// $string 尾部添加一个 <br /> 标签。
$string ereg_replace("$""<br />"$string); 

// 删除 $string 里的换行符。
$string ereg_replace("\n"""$string);
?>
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/regex.examples.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3