博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php 锚点_使用PHP分配锚点ID
阅读量:2518 次
发布时间:2019-05-11

本文共 906 字,大约阅读时间需要 3 分钟。

php 锚点

Last week, to create a PHP script that finds anchors in an HTML document and assigns an ID to the element IF the element doesn't have an ID already. stepped up to the challenge.

上周, ,要求他们创建一个PHP脚本,该脚本可在HTML文档中找到锚点,如果该元素还没有ID,则为该元素分配一个ID。 ( 加紧了挑战。

PHP (The PHP)

function anchor_fix($anchor){  // the match comes as an array  // the whole match (what we want) is the 0th element  if (! preg_match('/\sid="/i', $anchor[0])) {	 return preg_replace('/name="([^"]*)"/i', 'id="$1" $0', $anchor[0]);  } else {	 // already has an id!	 return $anchor[0];  }}/* usage */echo preg_replace_callback('/
]*>/i', 'anchor_fix', file_get_contents('page.html'));

结果 (The Result)

		this is an anchor some text... another one...		

... becomes ...

...变成...

		this is an anchor some text... another one...		

Great job Jeremy!

杰里米(Jeremy)做得好!

翻译自:

php 锚点

转载地址:http://wgswd.baihongyu.com/

你可能感兴趣的文章
太过于依赖.NET默认的序列化机制
查看>>
Alpine Linux 2.5.0 发布,面向路由器、防火墙
查看>>
quotatool 1.6.2 发布,磁盘配额管理工具
查看>>
CVSps 3.8 发布,CVS 资料库更改收集
查看>>
构造函数,析构函数是否为虚函数
查看>>
Django缓存使用方法
查看>>
html布局
查看>>
并查集
查看>>
高性能HTTP加速器Varnish(概念篇)
查看>>
Linux 如何写makefile文件
查看>>
flutter_webview_plugin 无法加载网页的异常处理
查看>>
bloc控制读写文件
查看>>
微信小程序
查看>>
预培训-阅读-快速阅读并提问
查看>>
拓展KMP以及模板
查看>>
洛谷 P3049 Landscaping ( 贪心 || DP)
查看>>
洛谷 P1059 明明的随机数
查看>>
python 基础大纲
查看>>
window自动任务实现数据库定时备份
查看>>
Windows 7 Ultimate(旗舰版)SP1 32/64位官方原版下载(2011年5月12日更新版)
查看>>