preg-match

preg_match unicode parsing

落花浮王杯 提交于 2019-12-11 08:33:17
问题 I want to match a sub set of unicode/UTF-8 chars, (marked in yellow here http://solomon.ie/unicode/), from my research I came up with this: // ensure it's valid unicode / get rid of invalid UTF8 chars $text = iconv("UTF-8","UTF-8//IGNORE",$text); // and just allow a basic english...ish.. chars through - no controls, chinese etc $match_list = "\x{09}\x{0a}\x{0d}\x{20}-\x{7e}"; // basic ascii chars plus CR,LF and TAB $match_list .= "\x{a1}-\x{ff}"; // extended latin 1 chars excluding control

Extracting values from string with PHP [duplicate]

喜欢而已 提交于 2019-12-11 08:19:17
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Preg_match_all <a href How to parse and process HTML with PHP? I have used curl to extract the source of a page and need to extract some values from the curl output. Part of the output looks like this: <div class="detailInfo"> <label>Manufacturer code/Gas council no: </label>BKSWX5506</div> <div class="detailInfo"></div> <div class="detailInfo"> <div> <label>Retail price:</label><span>£12.30</span> </div> <div>

universal regex code

◇◆丶佛笑我妖孽 提交于 2019-12-11 07:20:13
问题 I am a beginner in web development especially in the regex code and want to know if it is possible to write a universal code that will retrieve the coordinates of the sites regardless of whether they are in the iframe code or image URL or in javascript. <div id="g_map"></div> <script src="http://maps.google.com/maps?file=api&v=2&key=key" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ var html = ''; var lat = 44.799439; var lang = 20.483494; if

Unknown modifier in preg_match() statement [duplicate]

本小妞迷上赌 提交于 2019-12-11 07:16:41
问题 This question already has answers here : Warning: preg_replace(): Unknown modifier ']' (3 answers) Closed 5 months ago . After 2 attempts (thanks to Stack Overflow) I finally got my regex url to work and blacklist specific things in different ways as I wanted. However, it doesn't work properly, whilst yes; it does blacklist the words and prevent them being entered into the database, it throws up an error: PHP Warning: preg_match() [function.preg-match]: Unknown modifier '\\' in C:\wamp\www

validate password with preg_match in php

余生颓废 提交于 2019-12-11 06:27:31
问题 I need to validate passwords. I currently use: preg_match("/^[a-z0-9_-]*$/i", $pass) . I would like to add length to this. My mysql table is set up like this : userpassword varchar (40) NOT NULL, . So between 6 and 40 characters. And I would like to allow all characters that are not dangerous to put in my db. 回答1: Imposing arbitrary complexity rules on passwords is very user hostile and does not improve security substantially. Don't do it. Here's why I think the above statement is true: If I

what is the easiest way of getting a number from a url?

回眸只為那壹抹淺笑 提交于 2019-12-11 06:16:09
问题 I am hoping someone can help me, I have created url's like this /this/is/a/test/index.asp /this/is/a/test/index-1.asp /this/is/a/test/index-2.asp /this/is/a/test/index-3.asp What is the easiest way to strip the number from the URL? Instead of using variables like this: /this/is/a/test/index.asp?no=1 /this/is/a/test/index.asp?no=2 /this/is/a/test/index.asp?no=3 to create variables I am using the number in the URL to dynamically call the content on the page. If the url is: /this/is/a/test/index

PHP Regex for a string with alphanumeric and special characters

老子叫甜甜 提交于 2019-12-11 05:49:59
问题 I tried and could not find an answer for this issue, so I'm asking this question. I need to create a regex for password validation and it must have following conditions. At least one letter At least one number At least one special letter ~ ! ^ ( ) { } < > % @ # & * + = _ - Must not contain $ ` , . / \ ; : ' " | Must be between 8-40 characters No spaces I have created following regex but it does not work properly. preg_match('/[A-Za-z\d$!^(){}?\[\]<>~%@#&*+=_-]{8,40}$/', $newpassword) Can

regex to print url from any webpage with specific word in url

淺唱寂寞╮ 提交于 2019-12-11 05:05:47
问题 i am using below code to extract url from a webpage and its working just fine but i want to filter it. it will display all urls in that page but i want only those url which consists of the word "super" $regex='|<a.*?href="(.*?)"|'; preg_match_all($regex,$result,$parts); $links=$parts[1]; foreach($links as $link){ echo $link."<br>"; } so it should echo only uls where the word super is present. for example it should ignore url http://xyz.com/abc.html but it should echo http://abc.superpower.com

preg_match considers special characters as a separate word

馋奶兔 提交于 2019-12-11 04:58:27
问题 I have a regex for cut a string in a way to contain a keyword (the keyword is based on a pattern, like {query:ABCD:1234}), 5 words before the keyword and 5 words after it. Then before and after that keyword, I am going to show three dots, like: Lorem ipsum dolor sit amet, consectetur {query:ABCD:1234} adipiscing elit. Mauris consequat, quam id feugiat varius. And I expect: ... ipsum dolor sit amet, consectetur {query:ABCD:1234} adipiscing elit. Mauris consequat, quam ... Here is the regex:

preg_match() find all values inside of table?

泪湿孤枕 提交于 2019-12-11 04:35:47
问题 hey guys, a curl function returns a string $widget that contains regular html -> two divs where the first div holds a table with various values inside of <td> 's. i wonder what's the easiest and best way for me to extract only all the values inside of the <td> 's so i have blank values without the remaining html. any idea what the pattern for the preg_match should look like? thank you. 回答1: You're betting off using a DOM parser for that task: $html = <<<HTML <div> <table> <tr> <td>foo</td>