|
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_...
|
|
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....
|
|
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="' .
|
Ask your Facebook Friends
|
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.
|
|
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....
|
|
I am trying to grab the capital letters of a couple of words and wrap them in spans. I am using preg_replace, but it's not outputting anything.
preg_replace("/[A-Z]/", "<span class=\"initial\">$1</span>", $str)
Started by Flubba on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
preg....
You need to put the match in parentheses, like this:
preg_replace("/([A-Z])/", "<span class=\"initial\">$1</span>", $str) From the preg_replace documentation on php.net:
replacement may capture using parenthesis.
|
|
Hello again.
$string = preg_replace("#\[name=([a-zA-Z0-9 .-]+)*]#",'<td><a href="' . "$front_page/" . str_replace(' ', '-', "$1") . '">'."$1</a></td>",$string);
This part of script doesn't work:
str_replace(' ', '-', "$1")
I need...
Started by ciss on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The e modifier in your regular expression :
$string = preg_replace("#\[name=([a-zA-Z0-9 .-]+)*]#e;"', $string);
Or by using preg_replace_callback :
function callbackFunction($match) { global $front_page].'</a></td>'; } $string....
|