正则表达式如何匹配两种情况
我的链接存在这二个情况
1,$str=xxx.php?a=aaa;
2,$str=xxx.php?a=aaa&m=bbb;
我自己写的正则,但匹配不到,求高手帮助写一下:
preg_match("/((.*?\.php)\?(.*))(?(&.*))/is",$str,$arr);
想要的结果:当链接后面存在 &m=xxx 时,把 这里的结果也分段出来,不存在就只配置前面的
回复讨论(解决方案)
你的意思是如果第二种情况就取出bbb第一种情况就取出aaa对吧?
你的意思是如果第二种情况就取出bbb第一种情况就取出aaa对吧?
对,是的,
为什么不用parse_url呢?结合explode分析你的query里面有多少个参数,效率比用正则要高的多
1,$str=xxx.php?a=aaa;
2,$str=xxx.php?a=aaa&m=bbb;
不要硬套正则有些时候正则未必方便
$val=end(explode('=',$str));
我以为正则的效率很高呢,所以……
自学的小白还有很多路要走,谢谢你们的指点!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Alipay PHP...
