|
Hi,
I get this warning from php after the change from split to preg_split for php 5.3 compatibility :
PHP Warning: preg_split(): Delimiter must not be alphanumeric or backslash
the php code is :
$statements = preg_split("\\s*;\\s*", $content);
How can...
Started by benjisail on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
However, PHP itself doesn't support this ....
Functions) inherit this.
preg_split("/\s*;\s*/", $content);
Although the question was tagged as answered two minutes after:
/\s*;\s*/Ui
PHP's Perl-compatible regular expressions (aka preg_...
|
|
Hello,
I have some data similar to this:
aaa1|aaa2|ZZZ|aaa3|aaa4|aaa5|ZZZ|aaa6|aaa7
I want to match all "aaa[0-9]" BETWEEN "ZZZ" (not the ones outside).
So I have some PHP code: $string = "aaa1aaa2zzzzaaa3aaa4aaa5zzzzaaa6aaa7"; preg_match_all("/zzzz.*...
Started by Jamie on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
If (preg_match('/zzzz(.*?)zzzz/', $string, $matches)) { preg_match_all('/(aaa\d)/', $matches[1 = "aaa1aaa2zzzzaaa3aaa4aaa5zzzzaaa6aaa7"; preg_match_all("/aaa[0-9](?=.*?zzzz)(?!(?>.*?zzzz).*?zzzz)/", $string, $matches, PREG....
|
|
I'm trying to find some certain blocks in my data file and replace something inside of them. After that put the whole thing (with replaced data) into a new file. My code at the moment looks like this:
$content = file_get_contents('file.ext', true); //...
Started by Den Thomas on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
You don't even need the preg_replace; because you've already got the matches you can just use blocks first preg_match_all('/regexp/su', $content, $matches); foreach ($matches[0] as $match'); $content = preg_replace('/match/', 'replacement....
|
Ask your Facebook Friends
|
I'm trying to do a simple task of altering thousands of music video embed codes with a common with/height.
For example, I have the following code:
<object width="480px" height="407px" > <param name="allowFullScreen" value="true"/> <param...
Started by Yegor on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
$new_width.
Here's how to get the width and height
preg_match('/width="(\d+)(px)?" height="(\d+)(px)?"/', $text:
$text = preg_replace('/width="(\d+)(px)?" height="(\d+)(px)?"/', 'width="' .
|
|
I have a text file that I am displaying in a table. I am using preg_match_all to find a specific Title with a specific Chapter and I am replacing the Title and Chapter with preg_replace to make it a link..
For example the contents within the text file...
Started by D3V1NE on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Dec 04 12:13 50 x 50 44 STR; preg_match_all('/\w{3}\s\d{2}\s\d{2}:\d{2}\s(.+)?\s(\d{2,})/', $s, $m", $filedata); echo "<table border=\"1\">"; foreach($lines as $line) { echo "<tr>"; preg_match.
|
|
Hi , really simple question how can I preg_replace the backslash charactor ?
Started by Oliver Bayes-Shelton on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Alternatively....
Escape \ with \ : \\
preg_replace('/\\/', 'REMOVED BACKSLASH', 'sometest\othertest');
You need to escape the backslash: \\
From the manual on preg_replace() :
To use backslash in replacement, it must be doubled ("\\\\" PHP string).
|
|
How do I replace a single question mark with preg replace.
Started by stunnaman on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
preg_replace('/\?/', 'replacement', $original, 1)
If it's a single character you're replacing, you may not need a preg_ solution: a "simple" str_replace may do the trick as well:
www.php.net/str" $new = preg_replace('/(?<!\?)\....
|
|
Preg_match gives one match. Preg_match_all returns all matches. Preg_split returns all splits.
How can I split only the first match?
Example:
preg_split("~\n~",$string);
This is what I want:
array(0=>'first piece',1=>'the rest of the string without...
Started by albus on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Thanks to Ben James for mentioning:
preg_split array(substr($string,0,$fp), substr($string,$fp));
Or you can if you insist on preg_split(); :
$fp = strpos($string,"\n"); $arr = preg....
Simply set $limit to 2 for 2 parts of the array .
|
|
$line = "Hello World"; $line= preg_replace("/Hello/", $replacement, $line); - Works! $find = "Hello"; $line= preg_replace("/$find/", $replacement, $line); - Wont replace anything! $string = "Hello"; $find = "/".$string."/"; $line= preg_replace($find, ...
Started by Micah Potter on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
If you are using different strings, with special characters, be sure to run a preg."/"; print_r( preg_replace($find, $replacement, $line) ); ## output: Bye World
Can you provide more.
If they wouldn't.
|
|
How can i get 41P86246HOH7C1G4A983321910HDL63U9 from the following with preg_match
input type="text" value="41P86246HOH7C1G4A983321910HDL63U9" id=""
Answer Snippets (Read the full thread at stackoverflow):
Id=""'; $m = array(); if (preg_match('#value="([^"]+)"#', $str, $m)) { var_dump($m[1]); }
Which');
With something like this:
if(preg_match('@value="([^"]*)"@', $text, $m)){ echo $m[1]; }
But you){ $attrs = array(); if(preg_match....
|