PHP str_replace() 函数php
把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai":html
<?php echo str_replace("world","Shanghai","Hello world!"); ?>
PHP中一个好用的函数parse_url,特别方便用来作信息抓取的分析,举例子以下: 浏览器
$url = "http://www.daimajiayuan.com/course/"; $parts = parse_url($url);
输出:
Array
(
[scheme] => http
[host] => www.daimajiayuan.com 函数
[path] => /courseurl
)spa
又如:code
<?php $url = 'http://username:password@hostname/path?arg=value#anchor'; print_r(parse_url($url)); echo parse_url($url, PHP_URL_PATH); ?>
输出:
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
) htm
htmlspecialcharsci
把预约义的字符 "<" (小于)和 ">" (大于)转换为 HTML 实体:字符串
<?php $str = "This is some <b>bold</b> text."; echo htmlspecialchars($str); ?>
以上代码的 HTML 输出以下(查看源代码):
<!DOCTYPE html> <html> <body> This is some <b>bold</b> text. </body> </html>
以上代码的浏览器输出:
This is some <b>bold</b> text.