<ul class="main_con"> <li> <span class="kind"><a href="http://book.zongheng.com/store/c21/c1210/b9/u0/p1/v9/s9/t0/ALL.html" title="动漫同人" target="_blank">[动漫同人]</a></span> <span class="chap"> <a href="http://book.zongheng.com/book/299149.html" class="fs14" title="宠物小精灵黑白2" target="_blank">宠物小精灵黑...</a> <a href="http://book.zongheng.com/chapter/299149/5188596.html" title="正文 第二十二章 暗涌!" target="_blank">正文 第二十二...</a> </span> <span class="number"> 2826/18/0 </span> <span class="author"><a href="http://home.zongheng.com/show/userInfo/10996625.html" title="一鼎" target="_blank">一鼎</a></span> <span class="time">13-08-29 14:55</span> </li> <li> <span class="kind"><a href="http://book.zongheng.com/store/c31/c3106/b9/u0/p1/v9/s9/t0/ALL.html" title="青春校园" target="_blank">[青春校园]</a></span> <span class="chap"> <a href="http://www.mmzh.com/book/280776.html" class="fs14" title="那年雪花在飘,谁在忧伤?" target="_blank">那年雪花在飘...</a> <a href="http://book.zongheng.com/chapter/280776/5188594.html" title="正文 真诚璃茉与夜落雪的暗斗" target="_blank">正文 真诚璃茉...</a> </span> <span class="number"> 202/5/0 </span> <span class="author"><a href="http://home.zongheng.com/show/userInfo/9854181.html" title="蕾娜莎" target="_blank">蕾娜莎</a></span> <span class="time">13-08-29 14:55</span> </li>
以上代码中我只想要(.*)和这个格式一样的URL。这正则怎么写。
以下是我写的,
$html=file_get_contents($setting['book_url']);
$k='/
- ';
-
[动漫同人]
宠物小精灵黑...
正文 第二十二...
2826/18/0
一鼎
13-08-29 14:55
-
[青春校园]
那年雪花在飘...
正文 真诚璃茉...
202/5/0
蕾娜莎
13-08-29 14:55
$k.='(.*)(.*)(.*)';
$k.='/isU';
preg_match_all($k,$html,$rs);
没有匹配到地址
回复讨论(解决方案)
preg_match_all('#(.*?)#i',$html,$rs);
那直接写就是了
#(.*)#
<ul class="main_con"> <li> <span class="kind"><a href="http://book.zongheng.com/store/c21/c1210/b9/u0/p1/v9/s9/t0/ALL.html" title="动漫同人" target="_blank">[动漫同人]</a></span> <span class="chap"> <a href="http://book.zongheng.com/book/299149.html" class="fs14" title="宠物小精灵黑白2" target="_blank">宠物小精灵黑...</a> <a href="http://book.zongheng.com/chapter/299149/5188596.html" title="正文 第二十二章 暗涌!" target="_blank">正文 第二十二...</a> </span> <span class="number"> 2826/18/0 </span> <span class="author"><a href="http://home.zongheng.com/show/userInfo/10996625.html" title="一鼎" target="_blank">一鼎</a></span> <span class="time">13-08-29 14:55</span> </li> <li> <span class="kind"><a href="http://book.zongheng.com/store/c31/c3106/b9/u0/p1/v9/s9/t0/ALL.html" title="青春校园" target="_blank">[青春校园]</a></span> <span class="chap"> <a href="http://www.mmzh.com/book/280776.html" class="fs14" title="那年雪花在飘,谁在忧伤?" target="_blank">那年雪花在飘...</a> <a href="http://book.zongheng.com/chapter/280776/5188594.html" title="正文 真诚璃茉与夜落雪的暗斗" target="_blank">正文 真诚璃茉...</a> </span> <span class="number"> 202/5/0 </span> <span class="author"><a href="http://home.zongheng.com/show/userInfo/9854181.html" title="蕾娜莎" target="_blank">蕾娜莎</a></span> <span class="time">13-08-29 14:55</span> </li>
以上代码中我只想要(.*)和这个格式一样的URL。这正则怎么写。
以下是我写的,
$html=file_get_contents($setting['book_url']);
$k='/
- ';
$k.='(.*)(.*)(.*)';
$k.='/isU';
preg_match_all($k,$html,$rs);
没有匹配到地址
那是当然啦你的正则表达式是‘/
- (.*)(.*)(.*)/isU’
- 之后的.*不匹配换行符,而html代码中
- 后面有若干空格还有换行符
要是你想获取class="main_con"的ul里面的 的话建议你用jquery处理,它提供了多种选择器,类选择器,属性选择器...
test.php
$str=
html;
$pattern="/
preg_match_all($pattern,$str,$matches);
var_dump($matches[1]);
?>
$matches[1]就是你要的url数组
#(.*)#

DependencyInjection(DI)inPHPenhancescodeflexibilityandtestabilitybydecouplingdependencycreationfromusage.ToimplementDIeffectively:1)UseDIcontainersjudiciouslytoavoidover-engineering.2)Avoidconstructoroverloadbylimitingdependenciestothreeorfour.3)Adhe

到Improveyourphpwebsite的实力,UsEthestertate:1)emplastOpCodeCachingWithOpcachetCachetOspeedUpScriptInterpretation.2)优化的atabasequesquesquesquelies berselectingOnlynlynnellynnessaryfields.3)usecachingsystemssslikeremememememcachedisemcachedtoredtoredtoredsatabaseloadch.4)

是的,itispossibletosendMassemailswithp.1)uselibrarieslikeLikePhpMailerorSwiftMailerForeffitedEmailSending.2)enasledeLaysBetemailStoavoidSpamflagssspamflags.3)sylectynamicContentToimpovereveragement.4)

DependencyInjection(DI)inPHPisadesignpatternthatachievesInversionofControl(IoC)byallowingdependenciestobeinjectedintoclasses,enhancingmodularity,testability,andflexibility.DIdecouplesclassesfromspecificimplementations,makingcodemoremanageableandadapt

使用PHP发送电子邮件的最佳方法包括:1.使用PHP的mail()函数进行基本发送;2.使用PHPMailer库发送更复杂的HTML邮件;3.使用SendGrid等事务性邮件服务提高可靠性和分析能力。通过这些方法,可以确保邮件不仅到达收件箱,还能吸引收件人。

计算PHP多维数组的元素总数可以使用递归或迭代方法。1.递归方法通过遍历数组并递归处理嵌套数组来计数。2.迭代方法使用栈来模拟递归,避免深度问题。3.array_walk_recursive函数也能实现,但需手动计数。

在PHP中,do-while循环的特点是保证循环体至少执行一次,然后再根据条件决定是否继续循环。1)它在条件检查之前执行循环体,适合需要确保操作至少执行一次的场景,如用户输入验证和菜单系统。2)然而,do-while循环的语法可能导致新手困惑,且可能增加不必要的性能开销。

在PHP中高效地哈希字符串可以使用以下方法:1.使用md5函数进行快速哈希,但不适合密码存储。2.使用sha256函数提高安全性。3.使用password_hash函数处理密码,提供最高安全性和便捷性。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

禅工作室 13.0.1
功能强大的PHP集成开发环境

SublimeText3汉化版
中文版,非常好用