in Education by
This question already has answers here: How can I convert ereg expressions to preg in PHP? (4 answers) Closed 2 years ago. I'm sorry to ask a question but I am useless when it comes to understanding regex code. In a php module that I didn't write is the following function function isURL($url = NULL) { if($url==NULL) return false; $protocol = '(http://|https://)'; $allowed = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; $regex = "^". $protocol . // must include the protocol '(' . $allowed . '{1,63}\.)+'. // 1 or several sub domains with a max of 63 chars '[a-z]' . '{2,6}'; // followed by a TLD if(eregi($regex, $url)==true) return true; else return false; } Can some kind soul give me the replacement code for that with whatever is required to replace the eregi JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Good question - this is needed when you upgrade to PHP 5.3, where ereg and eregi functions are deprecated. To replace eregi('pattern', $string, $matches) use preg_match('/pattern/i', $string, $matches) (the trailing i in the first argument means ignorecase and corresponds to the i in eregi - just skip in case of replacing ereg call). But be aware of differences between the new and old patterns! This page lists the main differences, but for more complicated regular expressions you have to look in more detail at the differences between POSIX regex (supported by the old ereg/eregi/split functions etc.) and the PCRE. But in your example, you are just safe to replace the eregi call with: if (preg_match("%{$regex}%i", $url)) return true; (note: the % is a delimiter; normally slash / is used. You have either to ensure that the delimiter is not in the regex or escape it. In your example slashes are part of the $regex so it is more convenient to use different character as delimiter.)

Related questions

0 votes
    A bag contains 5 red marbles and 3 black marbles. Three marbles are drawn one by one without replacement. What is ... marble is red? Select the correct answer from above options...
asked Nov 20, 2021 in Education by JackTerrance
0 votes
0 votes
    A bag contains 5 red and 3 blue balls. If 3 balls are drawn at random without replacement the probability that exactly ... /28 D. 5/28 Select the correct answer from above options...
asked Nov 20, 2021 in Education by JackTerrance
0 votes
0 votes
    Two integers xandy are chosen with replacement out of the set {0,1,,2,3,10} . Then find the probability that |x-y ... 25 121 D. 20 121 Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    I want to submit some form information into my table, but this error is showing, if i do Route::resource('userinfo', ... can't insert data, what will be the solution. My controller...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I want to submit some form information into my table, but this error is showing, if i do Route::resource('userinfo', ... can't insert data, what will be the solution. My controller...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: PHP parse/syntax errors; and how to solve them (21 answers) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: PHP parse/syntax errors; and how to solve them (21 answers) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    There are 5 cards numbered 1 to 5, one number on one card. Two cards are drawn at random without replacement. ... and variance of X. Select the correct answer from above options...
asked Nov 20, 2021 in Education by JackTerrance
0 votes
    A box contains 5 red and 4 white marbles. Two marbles are drawn successively from the box without replacement and ... is also white is Select the correct answer from above options...
asked Nov 13, 2021 in Education by JackTerrance
...