Questions tagged [preg-grep]

prege_grep is a PHP function to filter array entries that match a regular expression.

prege_grep() is a function to filter array entries that match a -compatible regular expression ().

array preg_grep ( string $pattern , array $input [, int $flags = 0 ] )

Example

$arr = ["a", 1, "b", 2];
$newArr = preg_grep("/[a-z]/", $array);
print_r($newArr);

Result

Array ( 
    [0] => a 
    [2] => b 
)
42 questions
0
votes
1 answer

Find character before or after of string using preg_grep() in PHP

I need to find any character before or after of a word using PHP preg_grep() from array. I have a array like following $findgroup = array("aphp", "phpb", "dephpfs", "potatoes"); I need to find the values from the array which have 'php' word with a…
SuUbha
  • 167
  • 2
  • 15
0
votes
5 answers

PHP How to check if an array contains a pattern from another array

I'm looking for an alternative function that works the same as in_array but which could also check if the search term only contains a part of the given element instead of the whole element: Currently working with the following script: $attributes =…
Gianni
  • 19
  • 3
0
votes
3 answers

How to match two digits in pregmatch?

I have return a preg_match to check whether starting digits were 9477 or not and it works correctly. But now I want add another condition to add 9477 or 9476 should be valid. Here is the condition: should contain 11 digits should starts with 9477…
colombo
  • 520
  • 2
  • 9
  • 24
0
votes
1 answer

PHP preg_grep -> search array where search term contains special character

Trying to search an array that contains special characters: $array=array("0|0Name"=>"first name","0|1last"=>"last name","1|0email"=>"email address"); tried $v="0|0"; print_r(preg_grep("/^".$v.".*/",$array)); --->FAIL tried: …
dealerwrx
  • 3
  • 3
0
votes
1 answer

preg_grep with html source

I want extract this line

@include{"portal.shared.blook"}

using preg_grep("/(\s*@include.*)/",explode("\n", $Source)) from this source code hi

Hi I am layout

A.H
  • 1
  • 4
0
votes
1 answer

Array merge combination with foreach

What array management operations are needed? So, there are two arrays and I want to combine the following way: $arr Array ( [0] => 2015-08-16 22:12:04 [1] => 2015-08-16 13:20:17 [2] => 2015-08-16 11:45:47 [3] => 2015-08-16 02:35:12 …
Stanley
  • 17
  • 1
  • 6
0
votes
1 answer

preg_grep isn't working on multidimensional arrays

I've got an array of arrays called $jsonvpr. When trying to pull a preg_grep like preg_grep("/Jake.*.Peavy/i", $jsonvpr) it returns Notice: Array to string conversion in /var/www/html/crawlnew.php on line 310 a bunch of times (I supose once per…
0
votes
1 answer
-1
votes
1 answer

Return array with all data in key

I have this array $allYearData Now i´d like to split it into 12 parts, seperated by month. So i use PHP preg_grep() with a foreach loop to search for data. foreach($allYearData as $key){ $janData[] = preg_grep("/^2015-01-.*$/", $key); } How can…
Björn C
  • 3,860
  • 10
  • 46
  • 85
-1
votes
2 answers

How to use preg_grep to find urls

In my project i have mutiple .csv files with domain names like 1www.abc.com.csv, 2www.abc.com.csv,or 1m.xyz.com.au.csv, 2m.blackburneinvest.com.au.csv , 3m.blackburneinvest.com.au.csv I want to search the pattern *.csv(excluding number) in an…
Penny
  • 824
  • 1
  • 14
  • 31
-2
votes
3 answers

preg_grep() expects parameter 2 to be array, null given

I have a mySQL query to fetch data from a whole year: $allYearData = $stmt->fetchAll(); Now i´d like to split this array into 12 parts, separated by month. UPDATE So i count rows in $allYearData: //Count all keys $allYearDataCount =…
Björn C
  • 3,860
  • 10
  • 46
  • 85
-2
votes
2 answers

Get strings which are inside double braces

I have a string where some part of the string is inside braces, and I would like to get them in an array. The string is for example: Lorem {{ipsum}} dolor sit amet, {{consectetur}} adipiscing elit. And I would like to get: array("ipsum",…
Iter Ator
  • 8,226
  • 20
  • 73
  • 164
1 2
3