Home Backend Development PHP Tutorial PHP正则有关问题

PHP正则有关问题

Jun 13, 2016 am 10:19 AM
amp color match str

PHP正则问题
有两个链接,想将其中一个转换成另一个

HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->比如:链接A : http://user.qzone.qq.com/[color=#FF0000]1340477530[/color]#!app=2&pos=[color=#FF0000]1300412602[/color]链接B :http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?uin=[color=#FF0000]xxxxx[/color]&blogid=[color=#FF0000]yyyyyyy[/color]&numperpage=1000&property=GoRE
Copy after login

想将链接A的红色的部分换成链接B红色对应的部分,怎么弄啊。谢谢~~

------解决方案--------------------
uin 和 blogid 原来都应该是数值吧? 还是你的xxxx yyyy?
PHP code
$str1 = "http://user.qzone.qq.com/1340477530#!app=2&pos=1300412602";$str2 = "http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?uin=1111&blogid=2222&numperpage=1000&";preg_match('/([\d]+).*pos=([\d]+)$/', $str1, $match);if (isset($match[1]) && isset($match[2])) {    $pa=array('/uin=[\d]+/','/blogid=[\d]+/');    $re=array('uin='.$match[1],'blogid='.$match[2]);    $str2=preg_replace($pa,$re,$str2);    echo $str2;}<div class="clear">
                 
              
              
        
            </div>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What coin is AMP? What coin is AMP? Feb 24, 2024 pm 09:16 PM

What is AMP Coin? The AMP token was created by the Synereo team in 2015 as the main trading currency of the Synereo platform. AMP token aims to provide users with a better digital economic experience through multiple functions and uses. Purpose of AMP Token The AMP Token has multiple roles and functions in the Synereo platform. First, as part of the platform’s cryptocurrency reward system, users are able to earn AMP rewards by sharing and promoting content, a mechanism that encourages users to participate more actively in the platform’s activities. AMP tokens can also be used to promote and distribute content on the Synereo platform. Users can increase the visibility of their content on the platform by using AMP tokens to attract more viewers to view and share

Python built-in type str source code analysis Python built-in type str source code analysis May 09, 2023 pm 02:16 PM

1The basic unit of Unicode computer storage is the byte, which is composed of 8 bits. Since English only consists of 26 letters plus a number of symbols, English characters can be stored directly in bytes. But other languages ​​(such as Chinese, Japanese, Korean, etc.) have to use multiple bytes for encoding due to the large number of characters. With the spread of computer technology, non-Latin character encoding technology continues to develop, but there are still two major limitations: no multi-language support: the encoding scheme of one language cannot be used in another language and there is no unified standard: for example There are many encoding standards in Chinese such as GBK, GB2312, GB18030, etc. Since the encoding methods are not unified, developers need to convert back and forth between different encodings, and many errors will inevitably occur.

What are the similarities and differences between __str__ and __repr__ in Python? What are the similarities and differences between __str__ and __repr__ in Python? Apr 29, 2023 pm 07:58 PM

What are the similarities and differences between __str__ and __repr__? We all know the representation of strings. Python's built-in function repr() can express objects in the form of strings to facilitate our identification. This is the "string representation". repr() obtains the string representation of an object through the special method __repr__. If __repr__ is not implemented, when we print an instance of a vector to the console, the resulting string may be. >>>classExample:pass>>>print(str(Example()))>>>

Match matching method in java Match matching method in java Apr 28, 2023 pm 10:31 PM

Note that match is used for matching operations, and its return value is of boolean type. Through match, you can simply verify whether a certain element exists in the list. Example // Verify whether there is a string in the list starting with a, and match the first one, that is, return truebooleananyStartsWithA=stringCollection.stream().anyMatch((s)->s.startsWith("a"));System.out .println(anyStartsWithA);//true//Verify whether the string in the list

How to use regular expressions to match strings in Java? How to use regular expressions to match strings in Java? Apr 19, 2023 pm 02:37 PM

Concept 1. Various Match operations can be used to determine whether a given Predicate meets the elements of a Stream. 2. Match operation is a terminal operation and returns a Boolean value. Instance booleananyStartsWithA=stringCollection.stream().anyMatch((s)->s.startsWith("a"));System.out.println(anyStartsWithA);//truebooleanallStartsWithA=stringCollection.stream().

How to use java Match How to use java Match Apr 18, 2023 pm 01:55 PM

Concept 1. Various Match operations can be used to determine whether a given Predicate meets the elements of a Stream. 2. Match operation is a terminal operation and returns a Boolean value. Instance booleananyStartsWithA=stringCollection.stream().anyMatch((s)->s.startsWith("a"));System.out.println(anyStartsWithA);//truebooleanallStartsWithA=stringCollection.stream().

Retailer teases new color for iPhone 16 Pro phones and hints at camera upgrade Retailer teases new color for iPhone 16 Pro phones and hints at camera upgrade Sep 03, 2024 pm 12:47 PM

Apple's "It's Glowtime" event is set for September 9, and in this event, the company is expected to roll up the curtains of the iPhone 16 lineup. Per the recent leaks, the Pro phones in the series will be getting a new colorway, and this is

Google Pixel 9a: Leak points to larger casing and four colors Google Pixel 9a: Leak points to larger casing and four colors Oct 03, 2024 am 06:04 AM

The new design of the Google Pixel 9a has already been seen in initial photos and renders over the past few weeks, and nowAndroid Headlineshas just uncovered the exact dimensions and colors of the mid-range smartphone. The Pixel 9a measures 154 x 73

See all articles