preg-match

PHP: Text Processing preg_match function

喜欢而已 提交于 2019-12-08 13:10:57
问题 <?php $eqn1="0.068683000000003x1+2.046124y1+-0.4153z1=0.486977512"; preg_match("/\b[0-9]*\b/",$eqn1,$vx1); echo "X1 is: $vx1[0]"; ?> Can someone tell me, how to store the value of x1 (that is, 0.068683000000003) in the variable $vx1? The output is: X1 is: 0 回答1: 1)put semicolon after each sentences; 2)use echo "X1 is:" $vx1[0]; instead ofecho "X1 is: $vx1[0]"; <?php $eqn1="0.068683000000003x1+2.046124y1+-0.4153z1=0.486977512"; preg_match("/\b[0-9]*\b/",$eqn1,$vx1); echo "X1 is:" .$vx1[0]; 回答2

PHP preg_match_all html

删除回忆录丶 提交于 2019-12-08 09:39:53
问题 how can i create a preg_match_all regex pattern for php to give me this code? <td class="class2"> </td> <td class="class2" align="right"><span class="DarkText">I WANT THIS TEXT</span></td> To get me the text inside the span class? thanks! 回答1: You can use: preg_match_all("!<span[^>]+>(.*?)</span>!", $str, $matches); Then your text will be inside the first capture group (as seen on rubular) With that out of the way, note that regex shouldn't be used to parse HTML. You will be better off using

how to get link from img tag

断了今生、忘了曾经 提交于 2019-12-08 09:29:31
问题 $img = '<img src="http://some-img-link" alt="some-img-alt"/>'; $src = preg_match('/<img src=\"(.*?)\">/', $img); echo $src; I want to get the src value from the img tag and maybe the alt value 回答1: Assuming you are always getting the img html as you shown in the question. Now in the regular expression you provided its saying that, after the src attribute its given the closing tag for img. But in the string there is an alt attribute also. So you need to care about it also. /<img src=\"(.*?)\".

replacing all image src tags in HTML text

让人想犯罪 __ 提交于 2019-12-08 06:35:44
问题 I'm trying to make a simple php script to find all src attributes from all images in a html text and then replace all found srcs with some text after making some conditional changes. Something like this: @preg_match_all('/<img\s src="([a-zA-Z0-9\.;:\/\?&=_|\r|\n]{1,})"/isxmU', $body, $images); now i've all srcs into the $images variable, now i make: foreach ($images as $img) { ..my changes here.. } and now... how can i restore the changed srcs to the $body variable again?? many thanks in

PHP REGEX: Ignore + and #

混江龙づ霸主 提交于 2019-12-08 06:17:16
问题 So here is what I'm doing exactly: I have a form with a caption on the right of it, I want to write in the form only A-Z,0-9 and whitespaces, and for the caption I want to do the opposite, so if the user write's something wrong I can show what's the problem for example: "Invalid Charachter" But I'm stuck with + and # I want to ignore them too from the form with regular expression so I can show the "Invalid character" message for these too, as I saw php thinks that + sign is = to space ( ) or

Extract whatever is in brackets using regular expressions

不问归期 提交于 2019-12-08 05:40:25
问题 I really don't understand regex at all, and it hurts my head. I've a bit of text which looks like this blah blah blah (here is the bit I'd like to extract) ...and I don't really understand how to extract this using PHP's preg_split, or equivalent, command. How do I do this? And where's a good place to understand how preg works? 回答1: Something like this should do the trick, to match what is between ( and ) : $str = "blah blah blah (here is the bit I'd like to extract)"; if (preg_match('/\(([^\

Regex to find Youtube Link in string [duplicate]

纵饮孤独 提交于 2019-12-08 04:41:01
问题 This question already has answers here : How do I find all YouTube video ids in a string using a regex? (10 answers) Closed 4 years ago . I have a string like that: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, https://www.youtube.com/watch?v=7TL02DA5MZM when an unknown printer took a galley of type and scrambled it to make a type This is what I have: preg_match("(?:http://)?(?:www.)?(?

preg_match coordinates with degree sign

╄→尐↘猪︶ㄣ 提交于 2019-12-08 04:00:55
问题 I am trying to capture the coordinates of an input that could look like this 22°50'23.46"S, 43° 0'44.80"W or this 41°12'27.84"N, 16°18'40.15"E I think the problem is the degree symbols in my pattern. My current code: $found = preg_match("~(\d+\p{Sm}\d+\s*\'\s*\d+\s*\.\s*\d+\s*\"\s*[N|S])\s*,\s*(\d+\s*\p{Sm}\s*\d+\s*\'\s*\d+\s*\.\s*\d+\s*\"\s*[E|W])~i", $_POST['submission']['url'], $matches); $matches stays empty. 回答1: Perhaps you should try ignoring the actual degrees and tick marks and focus

Get number before selected word form string using preg_match function in php

泪湿孤枕 提交于 2019-12-07 22:25:56
问题 I am trying to get the mm and inches values from the following string using preg_match . $string = "Gold 5.0mm Rolo Chain 18" In"; How can I do this? 回答1: Regex: ([\d\.]+)(?:mm|\") ([\d\.]+)(?:mm|\") This will match digits , . before mm and " . PHP code demo <?php ini_set('display_errors', 1); $string='Gold 5.0mm Rolo Chain 18" In'; preg_match_all("/([\d\.]+)(?:mm|\")/", $string,$matches); print_r($matches);// its 1 index will return your desired result Or: Regex: /[\d\.]+(?=mm|\")/ [\d\.]+(?

Matching multiple occurrence of the same character with preg_match

♀尐吖头ヾ 提交于 2019-12-07 21:30:50
问题 how can i find multiple occurrence of the same character? something like: $maxRepeat = 3; "pool" passes "poool" don't i need this to work for any character, so i guess I'll have to escape special characters like . and \ which characters i have to escape? do you know any good reference to preg_match regexp apart from the one on php.net? 回答1: You use quantifiers for this preg_match("/p(o){1,3}ls/",$string); Excerpt: The following standard quantifiers are recognized: 1. * Match 0 or more times 2