首页 后端开发 php教程 匹配字符串解决办法

匹配字符串解决办法

Jun 13, 2016 pm 01:40 PM
content quot

匹配字符串
如何返回url呢???

传入字符串:

HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><a href="http://www.macaucentral.com/dev/index.php/beauty-content/6579-celina-beauty-centre">莎莉娜美容中心 Celina ...</a>


返回字符串
HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->http://www.macaucentral.com/dev/index.php/beauty-content/6579-celina-beauty-centre


------解决方案--------------------
PHP code
<?php $str='<a href="http://www.macaucentral.com/dev/index.php/beauty-content/6579-celina-beauty-centre">莎莉娜美容中心 Celina ...';
$pattern='/<a>]*href="([^"\']*)"/';
preg_match($pattern,$str,$matchs);
print_r($matchs);
<br><font color="#e78608">------解决方案--------------------</font><br>
preg_match('/href="([^"]*)"/',$str,$arr);<br>echo $arr[1]; <div class="clear">
                 
              
              
        
            </div></a>
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Stock Market GPT

Stock Market GPT

人工智能驱动投资研究,做出更明智的决策

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

如何检查电子邮件地址在PHP中是否有效? 如何检查电子邮件地址在PHP中是否有效? Sep 21, 2025 am 04:07 AM

usefilter_var()

如何在PHP中制作对象的深度副本或克隆? 如何在PHP中制作对象的深度副本或克隆? Sep 21, 2025 am 12:30 AM

useunSerialize(serialize($ obj))fordeepcopyingwhenalldataiSerializable;否则,exhiment__clone()tomanallyDuplicateNestedObjectedObjectSandAvoidSharedReference。

如何合并PHP中的两个阵列? 如何合并PHP中的两个阵列? Sep 21, 2025 am 12:26 AM

usearray_merge()tocombinearrays,oftritingDupritingDuplicateStringKeySandReIndexingNumericKeys; forsimplerconcatenation,尤其是innphp5.6,usethesplatoperator [... $ array1,... $ array2]。

如何在PHP项目中使用名称空间? 如何在PHP项目中使用名称空间? Sep 21, 2025 am 01:28 AM

NamespacesinPHPorganizecodeandpreventnamingconflictsbygroupingclasses,interfaces,functions,andconstantsunderaspecificname.2.Defineanamespaceusingthenamespacekeywordatthetopofafile,followedbythenamespacename,suchasApp\Controllers.3.Usetheusekeywordtoi

PHP中的魔术方法是什么,并提供了'__call()和`__get()'的示例。 PHP中的魔术方法是什么,并提供了'__call()和`__get()'的示例。 Sep 20, 2025 am 12:50 AM

__call()methodistred prightedwhenaninAccessibleOrundEfinedMethodiscalledonAnaBject,允许customhandlingByAcceptingTheMethodNameAndarguments,AsshoheNpallingNengallingUndEfineDmethodSlikesayHello()

如何在PHP中获取文件扩展名? 如何在PHP中获取文件扩展名? Sep 20, 2025 am 05:11 AM

usepathinfo($ fileName,pathinfo_extension)togetThefileextension; itreliablyhandlesmandlesmultipledotsAndEdgecases,返回theextension(例如,“ pdf”)oranemptystringifnoneexists。

如何使用PHP更新数据库中的记录? 如何使用PHP更新数据库中的记录? Sep 21, 2025 am 04:47 AM

toupdateadatabaseRecordInphp,firstConnectusingpDoormySqli,thenusepreparedStatementStoExecuteAsecuteAsecuresqurupDatequery.example.example:$ pdo = newpdo(“ mySql:mysql:host = localHost; localhost; localhost; dbname; dbname = your_database = your_database',yous_database',$ username,$ username,$ squeaste;

MySQL条件聚合:使用CASE语句实现字段的条件求和与计数 MySQL条件聚合:使用CASE语句实现字段的条件求和与计数 Sep 16, 2025 pm 02:39 PM

本文深入探讨了在MySQL中如何利用CASE语句进行条件聚合,以实现对特定字段的条件求和及计数。通过一个实际的预订系统案例,演示了如何根据记录状态(如“已结束”、“已取消”)动态计算总时长和事件数量,从而克服传统SUM函数无法满足复杂条件聚合需求的局限性。教程详细解析了CASE语句在SUM函数中的应用,并强调了COALESCE在处理LEFT JOIN可能产生的NULL值时的重要性。

See all articles