473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

preg_replace() replacing all in loop

preg_match( "|<!-- InstanceBegin(.*)(-->)(.*)<!-- InstanceEnd -->|U",
$contents, $matches );

$my_template = $matches[0];
preg_match_all( "|<!-- InstanceBeginEditable(.*)(-->)(.*)<!--
InstanceEndEditable -->|U", $my_template, $editables );

$keys = array_keys( $editables[1] ); // from the editable region
names
foreach ($keys as $key)
{
$k = trim( ereg_replace( '["]', "", $key ) );

$on_mouse_over = "onMouseOver=hi_frame('$k');";
$on_mouse_out = "onMouseout=lo_frame('$k');";
$on_mouse_click =
"onClick=url_refresh('?option=com_oscar&task=edita rea&area=".urlencode($k)."');";
$new_contents = "<div id=$k $on_mouse_over $on_mouse_out
$on_mouse_click>". $editables[0][$k] ."</div>";
$pattern = "|<!-- InstanceBeginEditable(.*)(-->)(.*)<!--
InstanceEndEditable -->|U";
$placeholder = "<!--%ed".$k."-->";
$replaced_editables = preg_replace($pattern, $placeholder,
$my_template);

}

I want to loop through a string and replace the first instance of the
reg with <!--%ed0--> and the second with <!--%ed1--> etc untill the
loop has finished. But when I look at the output, the file is filled
with the last number - any ideas?

thanks

Jul 17 '05 #1
1 2336
si*******@gmail.com wrote:
[snip]

If you want to post code: make it easy to read: compact and snip the
irrelevant stuff.
I want to loop through a string and replace the first instance of the
reg with <!--%ed0--> and the second with <!--%ed1--> etc untill the
loop has finished. But when I look at the output, the file is filled
with the last number - any ideas?


Then your code is not complete, I don;'t see any line that outputs
anything. All T see is 1 preg_replace overwriting the same variable
again and again.

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Justin Koivisto | last post by:
I am replacing a string in a text block that has a literal $ in it, and preg_replace is seeing it as a backreference. Here is what I am using: foreach($price_lists as $list)...
1
by: Richard B. Christ | last post by:
I wrote the following code and it does NOT seem to work. $search = array('/<popup*>/ie'); $replace = array('make_popup(split_tag(\\0))'); preg_replace($search, $replace, $someText); If I try...
6
by: JDJones | last post by:
Just want to verify. I have a form and I want to parse any semi-colons out of the submitted info and replace with commas. Would this be the correct way to do it? $question1 = preg_replace(";",...
2
by: Brian Richmond | last post by:
I found this code in a PERL script that was written by someone else: $password =~ tr/a-zA-Z/n-za-mN-ZA-M/; For example, "newuser1" translates to "arjhfre1" and vice versa. I realize this...
2
by: Afkamm | last post by:
Hi, :) The preg_replace function... preg_replace(pattern, replacement, subject ) How on earth do you get the limit value to work with arrays? In my code both the pattern and replacement...
2
by: Thomas Schandl | last post by:
Hi! When replacing with preg_replace e. g.: $Month_Strings = array('/Jan/','/Feb/','/Mar/','/Apr/','/May/','/Jun/', '/Jul/','/Aug/','/Sep/','/Oct/','/Nov/','/Dec/'); $Month_Numbers =...
22
by: stoppal | last post by:
need to extract all text between the following strings, but not include the strings. "<!-- #BeginEditable "Title name" -->" "<p align="center">#### </p>" I am using preg_match(????, $s,...
1
by: zorro | last post by:
and does testing merely mean running it 100 000 times and clocking it? // using preg_replace : $s = ' <select name="color"> <option value="">choose <option value="red">red <option...
2
by: nobugus | last post by:
Hello, This might be more of a PHP-thing than REGEX, but here's my problem: I am using a HEX value to find and replace 'white spaces' with 'x': take this example: $string = preg_replace('//u',...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.