Replace url parameters with regular expression
Mar 29, 2018 am 10:46 AM這次給大家?guī)碛?a href="http://www.miracleart.cn/wiki/588.html" target="_blank">正則表達式替換url參數(shù),用正則表達式替換url參數(shù)的注意事項有哪些,下面就是實戰(zhàn)案例,一起來看一下。
具體代碼如下所示:
/*?定義替換對象鍵值?*/ var?setReferArgs?=?function(){ ?var?referArgs?=?new?Object(); ?referArgs['#userID\#']?=?userId; ?referArgs['\#userName\#']?=?userName; ?return?referArgs; } /*?替換URL的參數(shù)?*/ var?replaceUrlParams?=?function(url){ ?var?actualUrl?=?""; ?var?referArgs?=?setReferArgs(); ?for(var?key?in?referArgs){ ?var?e?=?eval('/'+?key?+'/g');? ?actualUrl?=?url.replace(e,referArgs[key]); ?url?=?actualUrl; ?} ?return?actualUrl; }
栗子:
?“http://10.0.0.250:8088/test?uesrID=#userID#” 替換成對應數(shù)值 “http://10.0.0.250:8088/test?uesrID=12345”;
?“http://10.0.0.250:8088/test/#userID#” 替換成對應數(shù)值 “http://10.0.0.250:8088/12345”;
延伸:
js使用正則表達式從url中獲取參數(shù)值
//從url中獲取參數(shù)值 ?function?getvl(name)?{ ?var?reg?=?new?RegExp("(^|\\?|&)"+?name?+"=([^&]*)(\\s|&|$)",?"i"); ?if?(reg.test(location.href))?return?unescape(RegExp.$2.replace(/\+/g,?"?")); ?return?""; ?}; ?var?code?=?getvl("code");
相信看了本文案例你已經(jīng)掌握了方法,更多精彩請關注php中文網(wǎng)其它相關文章!
推薦閱讀:
The above is the detailed content of Replace url parameters with regular expression. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

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

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)

i9-12900H is a 14-core processor. The architecture and technology used are all new, and the threads are also very high. The overall work is excellent, and some parameters have been improved. It is particularly comprehensive and can bring users Excellent experience. i9-12900H parameter evaluation review: 1. i9-12900H is a 14-core processor, which adopts the q1 architecture and 24576kb process technology, and has been upgraded to 20 threads. 2. The maximum CPU frequency is 1.80! 5.00ghz, which mainly depends on the workload. 3. Compared with the price, it is very suitable. The price-performance ratio is very good, and it is very suitable for some partners who need normal use. i9-12900H parameter evaluation and performance running scores

The latest official news of vivox200ultra has exposed the parameters and price details of vivox200ultra. It is reported that vivox200ultra will be equipped with a 10x periscope super telephoto lens, and the price starts at about 6999 yuan. It can be seen that it occupies an absolute advantage in photography performance. The following are the parameters and prices of vivox200ultra Come and see the details. 1. Parameter configuration details of vivox200ultra 1. Vivox200ultra rendering From the vivo X200 Ultra rendering, the front of the phone adopts a borderless full-screen design, and the visual effect of the entire front of the phone can be said to be very invincible. 2. vivox200ultra has Blackhawk frame

PyCharm is a commonly used Python integrated development environment with rich functions and shortcut keys that can help developers improve programming efficiency. In the daily programming process, mastering PyCharm's shortcut key replacement skills can help developers complete tasks more quickly. This article will introduce you to some commonly used replacement shortcut keys in PyCharm to help you easily improve your programming speed. 1.Ctrl+R replacement In PyCharm, you can use the Ctrl+R shortcut key to perform replacement operations.

C++ parameter type safety checking ensures that functions only accept values ??of expected types through compile-time checks, run-time checks, and static assertions, preventing unexpected behavior and program crashes: Compile-time type checking: The compiler checks type compatibility. Runtime type checking: Use dynamic_cast to check type compatibility, and throw an exception if there is no match. Static assertion: Assert type conditions at compile time.

An open source model that can beat GPT-4 has appeared! The latest battle report of the large model arena: the 104 billion parameter open source model CommandR+ climbed to 6th place, tying with GPT-4-0314 and surpassing GPT-4-0613. Image This is also the first open-weight model to beat GPT-4 in the large model arena. The large model arena is one of the only test benchmarks that the master Karpathy trusts. Image CommandR+ from AI unicorn Cohere. The co-founder and CEO of this large model startup is none other than Aidan Gomez, the youngest author of Transformer (referred to as the wheat harvester). As soon as this battle report came out, another wave of big model clubs started

jQuery is a classic JavaScript library that is widely used in web development. It simplifies operations such as handling events, manipulating DOM elements, and performing animations on web pages. When using jQuery, you often encounter situations where you need to replace the class name of an element. This article will introduce some practical methods and specific code examples. 1. Use the removeClass() and addClass() methods jQuery provides the removeClass() method for deletion

PyCharm is a powerful Python integrated development environment with rich functions and tools that can greatly improve development efficiency. Among them, the replacement function is one of the functions frequently used in the development process, which can help developers quickly modify the code and improve the code quality. This article will introduce PyCharm's replacement function in detail, combined with specific code examples, to help novices better master and use this function. Introduction to the replacement function PyCharm's replacement function can help developers quickly replace specified text in the code

PyCharm is an integrated development environment popular among programmers. It provides powerful functions and tools to make programming more efficient and convenient. In PyCharm, reasonable setting and replacement of shortcut keys is one of the keys to improving programming efficiency. This article will introduce how to replace shortcut keys in PyCharm to make programming more convenient. 1. Why should we replace shortcut keys? In PyCharm, shortcut keys can help programmers quickly complete various operations and improve programming efficiency. However, everyone has different habits, and some people may
