preg-match

preg_match to match substring of three numbers consecutively?

天大地大妈咪最大 提交于 2019-12-25 18:39:52
问题 I have a string $text_arr="101104105106109111112113114116117120122123124" fairly big string If i want to split three numbers from them like 101,104,105 and store them in $array .What should i do? I tried doing this: preg_match_all('/[0-9]{3}$/',"$text_arr",$array); 回答1: The easiest way to do this is with preg_split()Docs: $result = preg_split('/(\d{3})/', $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); See it working, or the result: Array ( [0] => 101 [1] => 104 [2] => 105 [3] =>

How to use preg match in array?

雨燕双飞 提交于 2019-12-25 18:21:13
问题 If I have an array: Array ( [0] => Array ( [0] => |174|September|2001| [1] => |Pengantar=Hello!!!! [2] => |Tema= Sami Mawon [3] => |Tema_isi=meet you!!! [4] => |Kutip=people [5] => |Kutip_kitab=Efesus [6] => |Kutip_pasal=4 [7] => |Kutip_ayat=28 [8] => |Tema_sumber=Kiriman dari Maurits albert (romind@ ) [9] => [[Kategori:e-humor 2001]] ) How can I get the value of Pengantar, Tema, Tema_isi etc? 回答1: You're going to have to loop over the array and use preg_match with a reference. Regex

how to remove only real duplicates from preg_match output?

大憨熊 提交于 2019-12-25 11:59:09
问题 Yes I know array_unique function, but the thing is that match might have a legitimate duplicates in my search term for example: $str = "fruit1: banana, fruit2: orange, fruit3: banana, fruit4: apple, fruit5: banana"; preg_match("@fruit1: (?<fruit1>\w+), fruit2: orange, fruit3: (banana), fruit4: (?<fruit4>apple), fruit5: (banana)@",$str,$match); array_shift($match); // I dont need whole match print_r($match); output is: Array ( [fruit1] => banana [0] => banana [1] => banana [fruit4] => apple [2

how can I sort properly with preg_match?

℡╲_俬逩灬. 提交于 2019-12-25 11:50:54
问题 I'm trying to modify a line in PHP file that deals with data that comes from XML(about 600 stations). The php make this data usable by a streamer media player. The original line is this if (($title <> "")&& (strpos($link,"<") === false)&& preg_match("/Cha/i",$lang)) this gives me about 50 stations, I want to add few stations that do not have "Cha" in $lang but "Soprts" and has "China" in their $title. So I wrote the line like this if (($title <> "")&& (strpos($link,"<") === false)&& preg

how can I sort properly with preg_match?

家住魔仙堡 提交于 2019-12-25 11:50:07
问题 I'm trying to modify a line in PHP file that deals with data that comes from XML(about 600 stations). The php make this data usable by a streamer media player. The original line is this if (($title <> "")&& (strpos($link,"<") === false)&& preg_match("/Cha/i",$lang)) this gives me about 50 stations, I want to add few stations that do not have "Cha" in $lang but "Soprts" and has "China" in their $title. So I wrote the line like this if (($title <> "")&& (strpos($link,"<") === false)&& preg

In PHP, how to preserve 1st part of a link, keep 2nd and dynamically change the rest

不打扰是莪最后的温柔 提交于 2019-12-25 09:16:27
问题 Foe example. Lets take 4 URLs (existing or future) that follow the targeted pattern of: https://KeepThisPartTill-cde.com/a/b/cde/ThisWillBeDifferent/ThisWillNot https://KeepThisPartTill-cde.com/a/b/cde/ThisIsDifferent/ThisWillNot https://KeepThisPartTill-cde.com/a/b/cde/ChangedAgain/ThisWillNot https://KeepThisPartTill-cde.com/a/b/cde/AndAgain/ThisWillNot So. If any of these (existing or future) links is clicked , we need them to be changed to: https://KeepThisPartTill-cde.com/a/b/cde

preg_match for a list of files extension

狂风中的少年 提交于 2019-12-25 08:56:28
问题 I would like to have your opinion on a simple regular expression I built to verify a list of comma separated file extensions (there could also be one or multiple spaces after or before the comma character). This regular expression should return the following values: $list = 'jpg,png,gif'; // valid $list = 'jpg , png, gif'; // valid $list = 'jpg'; // valid $list = 'jpg, png, gif'; // valid $list = 'jpg png, gif'; // INVALID $list = 'jpg png'; // INVALID I am using the regular expression below,

PHP preg_match meaning and issue

天涯浪子 提交于 2019-12-25 07:46:15
问题 Currently I have this code: <?php if (isset($_GET['id'])) { $itemid = $_GET['id']; $search = "$itemid"; $query = ucwords($search); $string = file_get_contents('http://clubpenguincheatsnow.com/tools/newitemdatabase/items.php'); if($itemid=="") { echo "Please fill out the form."; } else { $string = explode('<br>',$string); foreach($string as $row) { preg_match('/^(\D+)\s=\s(\d+)\s=\s(\D+)\s=\s(\d+)/', trim($row), $matches); if(strstr($matches[1], $query)) { echo "<a href='http:/

PHP preg_match meaning and issue

a 夏天 提交于 2019-12-25 07:42:28
问题 Currently I have this code: <?php if (isset($_GET['id'])) { $itemid = $_GET['id']; $search = "$itemid"; $query = ucwords($search); $string = file_get_contents('http://clubpenguincheatsnow.com/tools/newitemdatabase/items.php'); if($itemid=="") { echo "Please fill out the form."; } else { $string = explode('<br>',$string); foreach($string as $row) { preg_match('/^(\D+)\s=\s(\d+)\s=\s(\D+)\s=\s(\d+)/', trim($row), $matches); if(strstr($matches[1], $query)) { echo "<a href='http:/

How to parse a line and result in array - stuck

試著忘記壹切 提交于 2019-12-25 05:11:52
问题 Here's what I try to do : isNumeric(right(trim(contract_id),1)) isNumeric right trim contract_id 1 isNumeric(right(trim(contract_id),1), bob, george(five(four, two))) isNumeric right trim contract_id 1 bob george five four two So basiclly it take a line (let'say trim(var)) and will make an array of it (array(trim => array(var)). I did try with regex and strpos but no result... I need help. Thanks. 回答1: First off a descent parser will always give you better control. A whole regex solution