preg-match

php extract Emoji from a string

被刻印的时光 ゝ 提交于 2020-01-11 05:48:08
问题 I have a string contain emoji. I want extract emoji's from that string,i'm using below code but it doesn't what i want. $string = "😃 hello world 🙃"; preg_match('/([0-9#][\x{20E3}])|[\x{00ae}\x{00a9}\x{203C}\x{2047}\x{2048}\x{2049}\x{3030}\x{303D}\x{2139}\x{2122}\x{3297}\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}

Function ereg() is deprecated

六月ゝ 毕业季﹏ 提交于 2020-01-10 05:48:10
问题 I'm going through my code to replace any instances I'm using the ereg() function - which I was using for matching regex inside a string. I could use a little direction, if someone has a better method than what I'm using. Here's my old "currency validation" script: function valid_currency($number){ if(ereg('^[0-9]+\.[0-9]{2}$', $number)) return true; else return false; } if(valid_currency(25.30)){ echo "valid currency"; }else{ echo "invalid currency string"; } I replaced the ereg() with preg

Validate time format using preg_match

拜拜、爱过 提交于 2020-01-09 11:27:11
问题 I want to validate a time input (like 10:30 am, 02:30 pm) using preg_match() I use this, $pattern = "/([1-12]):([0-5])([0-9])( )(am|pm|AM|PM)/"; if(preg_match($pattern,$time)){ return true; } But when i give an input like 10:30 pmxxxx it will not validated. I dont know whether the method is correct or not. Help please. 回答1: The [...] notation in regexes defines character class: something that's applied to the single character. It's alternation that should be used here instead: 0[1-9]|1[0-2] .

Preg_replace and preg_match to get and replace HTML / PHP content

空扰寡人 提交于 2020-01-07 13:36:31
问题 I need to extract some HTML / PHP content and put it into an array. Here is what I have The code below is within a string called $string for example. <html> <?php myclass->my_function('First', 'Last'); ?> <p>Some other content</p> <?php myclass->my_function(1, 2, 3); ?> </html> I want to find all the values from the functions and sum them into an array with preg_match. Only myclass->my_function function values should be found. The array should look like this $array = array( 1 => array('First'

Preg_replace and preg_match to get and replace HTML / PHP content

浪子不回头ぞ 提交于 2020-01-07 13:36:11
问题 I need to extract some HTML / PHP content and put it into an array. Here is what I have The code below is within a string called $string for example. <html> <?php myclass->my_function('First', 'Last'); ?> <p>Some other content</p> <?php myclass->my_function(1, 2, 3); ?> </html> I want to find all the values from the functions and sum them into an array with preg_match. Only myclass->my_function function values should be found. The array should look like this $array = array( 1 => array('First'

Regular Expression to match dates in YYYY-MM-DD format

允我心安 提交于 2020-01-07 06:56:58
问题 I have a regular expression in PHP that looks for the date in the format of YYYY-MM-DD What I have is: [\d]{4}-[\d]{2}-[\d]{2} I'm using preg_match to test the date, the problem is that 2009-11-10 works, but 2009-11-1033434 works as well. It's been awhile since I've done regex, how do I ensure that it stops at the correct spot? I've tried doing /([\d]{4}-[\d]{2}-[\d]{2}){1}/ , but it returns the same result. Any help would be greatly appreciated. 回答1: What you need is anchors, specifically ^

Using regex to find value between square brackets [duplicate]

时间秒杀一切 提交于 2020-01-07 03:15:22
问题 This question already has answers here : regex to find string within square brackets [] (3 answers) Closed 5 years ago . I want to find the value inside square brackets. Let's say I have a string like this $str = "This is a test string. I want to get value between [this] and [/this]"; So, to explain it pretty clearly, I want to find [this] and [/this] and then the ' and ' between them. I found some threads here about finding the value inside square brackets but that's not exactly my case, and

Using regex to find value between square brackets [duplicate]

不打扰是莪最后的温柔 提交于 2020-01-07 03:14:25
问题 This question already has answers here : regex to find string within square brackets [] (3 answers) Closed 5 years ago . I want to find the value inside square brackets. Let's say I have a string like this $str = "This is a test string. I want to get value between [this] and [/this]"; So, to explain it pretty clearly, I want to find [this] and [/this] and then the ' and ' between them. I found some threads here about finding the value inside square brackets but that's not exactly my case, and

preg_match backreference to find ending tag

前提是你 提交于 2020-01-06 19:02:05
问题 I'm trying to use regex to parse a template I have. I want to find the _stop tag for the _start tag. I need to find the specific ones since there can be nested _stop and _start tags. The regex I'm using is /{(.*?)_start}.*{(\1_stop)}/s and throwing that into a preg_match And the template <div data-role="collapsible-set" class="mfe_collapsibles" data-theme="c" data-inset="false"> {MakeAppointment_start} <div id="appointmentHeading" data-action-id="appointmentNext" data-action-text="Next" data

preg_match backreference to find ending tag

丶灬走出姿态 提交于 2020-01-06 19:01:51
问题 I'm trying to use regex to parse a template I have. I want to find the _stop tag for the _start tag. I need to find the specific ones since there can be nested _stop and _start tags. The regex I'm using is /{(.*?)_start}.*{(\1_stop)}/s and throwing that into a preg_match And the template <div data-role="collapsible-set" class="mfe_collapsibles" data-theme="c" data-inset="false"> {MakeAppointment_start} <div id="appointmentHeading" data-action-id="appointmentNext" data-action-text="Next" data