preg-replace

Replace “//” with “/* */” in PHP? [closed]

99封情书 提交于 2020-01-17 18:08:09
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I'm working in a code to minify html/css/js but i got a problem. I need to replace // with /* and */. Example: $(funcion(){ // Do something }); Replace to: $(funcion(){ /* Do something */ }); How do that? 回答1: First, as was pointed out in the comments, if you're looking to reduce

How can I extract or preg_replace chinese characters in a string?

随声附和 提交于 2020-01-17 08:55:20
问题 I am currently have a list of string like this 蘋果,香蕉,橙。 榴蓮, 啤梨 鳳爪,排骨,雞排 24個男,2個女,30個老人 What I want to do is just explode all chinese and alphanumeric character from these strings. How can I replace all special characters like , , 。 / " and spaces with - or _ then extract all chinese character with explode() like $str = explode("-",$str); or $str = explode("_",$str); ? I am currently have a RegEx like this if(/^\S[\u0391-\uFFE5 \w]+\S$/.test(value))..... And I modified it into $str = preg

PHP: Correct regular expression for making every letter left of the first colon lowercase

徘徊边缘 提交于 2020-01-17 07:47:29
问题 $value='x-Cem-Date:Wed, 16 Dec 2009 15:42:28 GMT'; Right now I have: $value = preg_replace('/(^.+)(?=:)/e', "strtolower('\\1')", $value); this outputs $value='x-cem-date:wed, 16 dec 2009 15:42:28 GMT'; it should output: $value='x-cem-date:Wed, 16 Dec 2009 15:42:28 GMT'; 回答1: Your regular expression should be as follows: /(^.+?)(?=:)/ The difference is the +? character. The +? is non-greedy, meaning that it will find the LEAST amount of characters until the expression moves onto the next match

Make sure that string follows the required format

 ̄綄美尐妖づ 提交于 2020-01-17 06:08:10
问题 I am attempting to check if a string follows a certain format by checking that: item[]= is repeated four times item[]= is followed by a number and & symbol (e.g item[]=2& ), except the last number doesn't have & after it The numbers after item[]= consist of only either 1-4 and can be in any order, but not repeated Here are a few examples of how the string would look (as you can see, the order of the number changes) - note that there will only be one string at a time! 1) $list = 'item[]=1&item

PHP preg_replace: highlight whole words matching a key in case/diacritic-insensitive way

只谈情不闲聊 提交于 2020-01-16 15:47:04
问题 I need to highlight single words or phrases matching the $key (whole words, not substrings) in an UTF-8 $text. Such match has to be both case-insensitive and diacritic-insensitive. The highlighted text must remain as it was (including uppercase/lowercase characters and diacritical marks, if present). The following expression achieved half the goal: $text = preg_replace( "/\b($key)\b/i", '<div class="highlight">$1</div>', $text ); It's case insensitive and matches whole words but won't

PHP preg_replace: highlight whole words matching a key in case/diacritic-insensitive way

杀马特。学长 韩版系。学妹 提交于 2020-01-16 15:46:54
问题 I need to highlight single words or phrases matching the $key (whole words, not substrings) in an UTF-8 $text. Such match has to be both case-insensitive and diacritic-insensitive. The highlighted text must remain as it was (including uppercase/lowercase characters and diacritical marks, if present). The following expression achieved half the goal: $text = preg_replace( "/\b($key)\b/i", '<div class="highlight">$1</div>', $text ); It's case insensitive and matches whole words but won't

How to use regex to delete everything except some words? [duplicate]

我的梦境 提交于 2020-01-16 04:07:31
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Regular expression: match all words except I need your help for using Regex in PHP to negate a selection. So I have a string like this : "Hello my name is tom" What I need to do is to delete everything from this string witch is not "tom" or "jack" or "alex" so I tried : $MyString = "Hello my name is tom" print_r(preg_replace('#^tom|^jack|^alex#i', '', $MyString)); But it's not working... Can you help me with

how to select image src using PHP

╄→尐↘猪︶ㄣ 提交于 2020-01-15 18:54:36
问题 So i have some images with several forms like this : <a href="" class="link-img" alt=""> <img editable="true" style="display: block; cursor: default;" class="main-image" width="538" height="auto" src="src" alt="large image"> </a> and like this : <a href="" class="link link-img"> <img src="src" style="width: 100%; display: block; cursor: pointer;" editable="true" class="main-image imageLink" width="" height="auto" alt=""> </a> so my code to select the src image is : $c = preg_replace('/<a href

how to select image src using PHP

£可爱£侵袭症+ 提交于 2020-01-15 18:53:14
问题 So i have some images with several forms like this : <a href="" class="link-img" alt=""> <img editable="true" style="display: block; cursor: default;" class="main-image" width="538" height="auto" src="src" alt="large image"> </a> and like this : <a href="" class="link link-img"> <img src="src" style="width: 100%; display: block; cursor: pointer;" editable="true" class="main-image imageLink" width="" height="auto" alt=""> </a> so my code to select the src image is : $c = preg_replace('/<a href

how to select image src using PHP

≯℡__Kan透↙ 提交于 2020-01-15 18:52:48
问题 So i have some images with several forms like this : <a href="" class="link-img" alt=""> <img editable="true" style="display: block; cursor: default;" class="main-image" width="538" height="auto" src="src" alt="large image"> </a> and like this : <a href="" class="link link-img"> <img src="src" style="width: 100%; display: block; cursor: pointer;" editable="true" class="main-image imageLink" width="" height="auto" alt=""> </a> so my code to select the src image is : $c = preg_replace('/<a href