preg-match

Hyperlink Youtube to Embed Code

假如想象 提交于 2019-12-12 06:16:50
问题 I've some troubles using Preg_replace and preg_match_all to convert a Youtube URL to embed code. Yes, I know that this topic has already touched in stackoverflow but not exactly like I want. I can get the ID from a url, without html, with that: http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)? But I've the url formatted with like this: <a href="http://www.youtube.com/watch?v=C9KAqhbIZ7o" class="comment-link">http://www.youtube.com/watch?v=C9KAqhbIZ7o</a> And I want to

Match all text between two HTML tags using a regex in PHP

夙愿已清 提交于 2019-12-12 06:13:34
问题 I have a problem with a regex pattern. It returns two arrays as a result... Here is my code: $code = preg_match_all("/\< style\>(.*?)\<\/style\>/",$code,$matches); var_dump($matches); As test I set: $code = ">< xxxxx> try blah fooo blah < /xxxxx> idfidf oh < x>< /x> < style> blah blah blah style1 < /style>< style>blah blah style 2 x< /style> It returns 2 arrays, I mean $matches = array 0 => array 0 => string '< style> blah blah blah style1 < /style>' (length=38) 1 => string '< style>blah blah

$_POST Number and Character checker

折月煮酒 提交于 2019-12-12 05:32:21
问题 This is a repeat question of Check $_POST['id'] is numeric then do this if not do otherwise But.. The answers given do not answer the question IMHO. The question is testing a $_POST string to see if it is a number or contains non-numeric characters. Not change the code to use $_GET. The original question is as such: if (!empty($_POST['id'])) { echo "empty"; } else { if (is_numeric($_POST['id'])) { echo "numeric!"; } else { echo "not empty but not numeric how come?"; } } I have tried, is

Nested Parentheses to Array using regex in PHP [duplicate]

拟墨画扇 提交于 2019-12-12 05:14:44
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Regular Expression to match outer brackets I have a string of the following format: (((aaa (bbb) ccc)(ddd (eee) fff) ggg)(hhh (iii) )(jjj (kkk) lll) mmm)(nnn (ooo) ppp)(qqq (rrr) sss) It basically has 3 main parts: (((aaa (bbb) ccc)(ddd (eee) fff) ggg)(hhh (iii) )(jjj (kkk) lll) mmm) (nnn (ooo) ppp) (qqq (rrr) sss) I need the search expression to get the 3 parts in an array (ignoring any sub parentheses). Once

Match String and Get Variable PHP

折月煮酒 提交于 2019-12-12 04:58:17
问题 I would like to be able to use this string to pull off a certain piece of data from a database '{my-id-1}' so basically if this is found in the text '{my-id-*}' then get the id (eg. if {is-id-1} then ID is 1) and then I can run some code with that ID. So I've got it so I can get the ID from the braces, but I'm not sure how to replace that within the text. <?php $text = "test 1 dfhjsdh sdjkfhksdhfkj skjh {is-id-1} sdfhskdfh sdfsdjfhksd fjksdfhksd {is-id-2}"; preg_match_all('/{is-id-+(.*?)}/',

How can I remove all non alpha numeric characters and leading zeros

谁说胖子不能爱 提交于 2019-12-12 04:55:02
问题 I want to remove everything from a string using regular expression except alpha and numeric characters and I need any leading zero removed. The below works but does not remove leading zeros $string = '00000000A1234567890-=qwesss €#¢∞§¶¶•ªº– ≠≠rtyuuiop[]\';lkjhgfdsazxcvbnm,./'; $pattern = '/([^\da-z]/i)'; $replacement = ''; echo preg_replace($pattern, $replacement, $string); How can i alter the pattern to remove leading Zeros? 回答1: This one will work: <?php $string = '00000000A1234567890-

Count unique appearance of substring in a list of words without knowing the substr?

↘锁芯ラ 提交于 2019-12-12 04:36:27
问题 * I try to count the unique appearances of a substring inside a list of words * So check the list of words and detect if in any words there are substrings based on min characters that occur multiple times and count them. I don't know any substrings. This is a working solution where you know the substring but what if you do not know ? Theres a Minimum Character count where words are based on. Will find all the words where "Book" is a substring of the word. With below php function. Wanted

preg_match to only allow https:// in an URL

感情迁移 提交于 2019-12-12 03:46:22
问题 I'd like to allow only https:// links to be used as remote avatar images in phpbb to avoid mixed content. This seems to be the code that is used to check whether the entered url is correct (to be found in /phpbb/avatar/driver/remote.php): if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.('. implode('|', $this->allowed_extensions) . ')$#i', $url)) { $error[] = 'AVATAR_URL_INVALID'; return false; } I'd like to add a if{}

Regex match string that ends with number

孤者浪人 提交于 2019-12-12 03:37:15
问题 What is a regex to match a string that ends with a number for example "c1234" - match "c12" - match "c" - no match Tried this but it doesn't work (?|c(?|[0-9]*$)) Thanks again, The beggining string needs to be specific too 回答1: Just use \d$ to check your string ends with a digit If you want your string to be a "c" followed by some digits, use c\d+$ 回答2: To match any string ending with a digit use: [\s\S]*\d$ if (preg_match('/[\s\S]*\d$/', $value)) { #match } else { #no match } 回答3: You can

Regular expression for email address in Arabic

主宰稳场 提交于 2019-12-12 02:14:59
问题 EDITED I googled to write a custom regular expression for my web application, and still I can't get what I wanted. I want to check if a string passes this pattern or not: *STRING*STRING INCLUDING ALL CHARS*STRING INCLUDING ALL CHARS# for example: *STRING*the first string تست یک*the second string تست دو# Should return TRUE *sdsdsd*the first string تست یکthe second string تست دو# should return FALSE(because it's not the pattern as *STRING*STRING*STRING#) $check = preg_match("THE RULE", $STRING)