preg-match

Warning: preg_match() [function.preg-match]: Unknown modifier 'v'

那年仲夏 提交于 2019-12-23 10:06:24
问题 I keep getting this error about 20 times in my wordpress blog about the same line of code. Here is the line of code that keeps getting the error. if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) ) $number = max($number, $matches[1]); What could be wrong? 回答1: Your regex will break if the string $id_base has a / in it as you are using / as the regex delimiter. To fix this use preg_quote on $id_base as: if (preg_match('/'. preg_quote($id_base,'/').'-([0-9]+)$/', .....) {

What is the preg_match_all `u` flag dependent on?

我与影子孤独终老i 提交于 2019-12-23 09:34:16
问题 I have some code in a PHP application that is returning null when I try and use it on the production server, but it works fine on the development server. Here is the line of code: // use the regex unicode support to separate the UTF-8 characters into an array preg_match_all( '/./us', $str, $match ); What is the u flag dependent on? I tested with mb_string enabled and disabled and it does not seem to affect it. The error I'm getting is preg_match_all: Compilation failed: unknown option bit(s)

PHP preg_match URL replacement usage

天涯浪子 提交于 2019-12-23 06:22:46
问题 I have two URL patten structure in $url news.oxo.com/site/data/html_dir/2013/05/25/2013052500007.html salute.com/arti/society/health/588947.html and want to change those to m.oxo.com/article.html?contid=2013052500007 m.salute.com/article.html?contid=2013052500007 I have tried <?php $url_m = preg_replace("salute.com","m.salute.com",$url); ?> <?php echo $url_m; ?> And I guess I am totally lost -_-;;;; Any help might be highly appreciated. 回答1: If you're responsible for both URLs and are using

PHP preg_match URL replacement usage

℡╲_俬逩灬. 提交于 2019-12-23 06:22:45
问题 I have two URL patten structure in $url news.oxo.com/site/data/html_dir/2013/05/25/2013052500007.html salute.com/arti/society/health/588947.html and want to change those to m.oxo.com/article.html?contid=2013052500007 m.salute.com/article.html?contid=2013052500007 I have tried <?php $url_m = preg_replace("salute.com","m.salute.com",$url); ?> <?php echo $url_m; ?> And I guess I am totally lost -_-;;;; Any help might be highly appreciated. 回答1: If you're responsible for both URLs and are using

preg_match using a variable?

房东的猫 提交于 2019-12-23 05:21:44
问题 here is what i want to try to do. I want an easy way to just add in new emails without having to have my client to have to touch the main code. $list= 'gmail|yahoo|aol'; $banned = '\b[\w\.-]+@((?!'.$list.').)[\w\.-]+\.\w{2,4}\b'; if ( isset($data['email']) && !preg_match($banned, $data['email']) ) {} or perhaps. do an include that points to a text file? with the domains listed inside? updated here is my code.. //Banned Domains $banned = 'mailexpire|spamtrail|0815'; // //Emails $email_list = '

php: split string into 3 parts by two delimiters where the first and the last “delimiters” are letters or numbers respectively

旧时模样 提交于 2019-12-23 02:58:18
问题 Any ideas how to split string into 3 parts where by two "delimiters" where the first and the last "delimiters" are letters or numbers respectively? $str = "%@-H-e-l-l-o-7-9#$%"; would be split like this: $arr=("%@-","H-e-l-l-o-7-9", "#$%"); and $str = "Hi$73"; would be split like this: $arr=("","Hi$73", ""); and $str = "Беларусь!"; would be split like this: $arr=("","Беларусь", "!"); and $str = "!"; would be split like this: $arr=("!","", ""); and $str = ""; would be split like this: $arr=(""

php: how to find numbers in string?

末鹿安然 提交于 2019-12-22 11:59:34
问题 I have some strings like: some words 1-25 to some words 26-50 more words 1-10 words text and words 30-100 how can I find and get from string all of the "1-25" and the "26-50" and more 回答1: If it’s integers, match multiple digits: \d+ . To match the whole range expression: (\d+)-(\d+) . Maybe you also want to allow whitespace between the dash and the numbers: (\d+)\s*-\s*(\d+) And maybe you want to make sure that the expression stands free, i.e. isn’t part of a word: \b(\d+)\s*-\s*(\d+)\b \b

PHP preg_match any character except word [duplicate]

大兔子大兔子 提交于 2019-12-22 08:40:47
问题 This question already has answers here : Regular expression to match a line that doesn't contain a word (29 answers) Regular Expression block negation (1 answer) Closed 6 years ago . To match any character except specified character (in this example "f") I use [^f]+ . But how to match any character except specified word? Something like [^word]+ Example: haystack : "bla1 bla2 bla3 bla4 hello bla5 bla6 bla7" (haystack contains HTML and newlines) needle : "bla1 bla2 bla3 bla4 " So I want to

Regular Expression to match unlimited number of options

送分小仙女□ 提交于 2019-12-22 05:24:06
问题 I want to be able to parse file paths like this one: /var/www/index.(htm|html|php|shtml) into an ordered array: array("htm", "html", "php", "shtml") and then produce a list of alternatives: /var/www/index.htm /var/www/index.html /var/www/index.php /var/www/index.shtml Right now, I have a preg_match statement that can split two alternatives: preg_match_all ("/\(([^)]*)\|([^)]*)\)/", $path_resource, $matches); Could somebody give me a pointer how to extend this to accept an unlimited number of

Capitalize first letter of a string (preceded with special characters) - PHP

放肆的年华 提交于 2019-12-21 17:45:10
问题 I'd like to capitalize a string like: ¿"hello"? I want my function to return ¿"Hello"? I've tried with regex and preg_match, with no luck... Here it is my previous question, related with this one: "preg_match is matching two characters when it should only match one" Thank you all! 回答1: You can do it using preg_replace_callback: preg_replace_callback('/^([^a-z]*)([a-z])/i', function($matches){ return $matches[1] . strtoupper($matches[2]); }, '¿"hello"?'); // ¿"Hello"? 回答2: Using preg_replace