473,396 Members | 2,099 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,396 software developers and data experts.

ereg_replace replaces to mutch

Hello,

I use a javascript ticker in my header which contains the news in a array
like that
tickercontents[0]='Message1'
tickercontents[1]='Message2'
tickercontents[2]='Message3'
now i want to write an easy script that i can run from my server to change
the message and
was thinking about something like that

$replacement = 'New Message1';
$file = "header.html";
$fh = fopen($file,"r") or die("can't open file");
$file = fread($fh, filesize($file)) or die("can't read file");
$replaced =
ereg_replace("(tickercontents\[0\]\=)(')(.*)(')","\\1\\2$ersatz\\4",$file1)
or die("can't do that sorry");
..........
the only problem is ereg_replace in not stopping at the end high coma in
message1 it stops at the end high coma of message3.
I there a way to make it stop after the first one.
I appreciate any thoughts
Thanks
chris
Jul 17 '05 #1
2 2170
Chris wrote:
ereg_replace("(tickercontents\[0\]\=)(')(.*)(')","\\1\\2$ersatz\\4",$file1) the only problem is ereg_replace in not stopping at the end high coma in
message1 it stops at the end high coma of message3.
I there a way to make it stop after the first one.
I appreciate any thoughts


Try:
preg_replace("/tickercontents\[0\]='([^']*)'/iU","tickercontents[0]='$ersatz'",$file1);

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #2
Rather than using replace

"Chris" <cm***@gmx.de> wrote in message
news:vq************@corp.supernews.com...
Hello,

I use a javascript ticker in my header which contains the news in a array
like that
tickercontents[0]='Message1'
tickercontents[1]='Message2'
tickercontents[2]='Message3'
now i want to write an easy script that i can run from my server to change
the message and
was thinking about something like that

$replacement = 'New Message1';
$file = "header.html";
$fh = fopen($file,"r") or die("can't open file");
$file = fread($fh, filesize($file)) or die("can't read file");
$replaced =
ereg_replace("(tickercontents\[0\]\=)(')(.*)(')","\\1\\2$ersatz\\4",$file1) or die("can't do that sorry");
.........
the only problem is ereg_replace in not stopping at the end high coma in
message1 it stops at the end high coma of message3.
I there a way to make it stop after the first one.
I appreciate any thoughts
Thanks
chris

A slight variation of your approach would be to use PHP as the Preprocessor
that it was designed as. This may not fit your requirements, but you then
again it may give you something to ponder:

In "header.php"

<html>
....
<script>
....
<?PHP
// Assume you ahve a list of message in the array $messageList
$index = 0;
foreach ($messageList as $message)
print "tickercontents[".$index++."]='".$message."'";
?>
...
</script>
.....

Good luck!
Christopher
Jul 17 '05 #3

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

Similar topics

1
by: Roland Sippel | last post by:
Is there anything change in "ereg_replace()" PHP > 4.3.2. Scripts works in PHP 4.3.1 but NOT in PHP 4.3.2: $text = "<!-- test -->"; $text = ereg_replace("]+"," ",strip_tags($text)); echo $text...
4
by: knocte | last post by:
Hello. I am testing this curious code and I don't understand yet why it doesn't work with the 2nd case: Case 1: $number = "2,4"; $number = ereg_replace(",",".",$number); echo $number; //...
0
by: Sean Pinto | last post by:
i am designing a search engine for our website. i want to allow for searchablity based on partial string match as well as quoted exact matches. for example the search search text many would...
3
by: Xaradas | last post by:
Someone could tell me why preg_replace eat a slash when it do replacement? <? $stringToReplace = "blah blah {nome} blah blah"; $replacement = "Two slash: \\\\"; $stringToReplace =...
2
by: kirill_uk | last post by:
hi, all, need your help guys! i have a variable $var = "one two"; i need to replace space betwin one and two with "+". any idea? thank you all
0
by: pieterprovoost | last post by:
Hi, I would like to use the ereg_replace() function to replace wiki-like syntax, for example: ] becomes <a href="index.php?page=somepage">somepage</a> **hello** becomes <i>hello</i>
1
by: tmcp | last post by:
Hello I'm a bit new to regular expressions and I'm having a problem I'm trying to strip any code which is inside a <p> tag for instance from <p style="margin: 0in 0in 0pt;" class="MsoNormal"> to...
2
by: encepif | last post by:
I think this is the right command., could someone please show me how to replace instances of a quote like this " with its html version - &quot;. I am mixed up with the escaping, etc. Thank you :-) ...
5
by: Hugh Oxford | last post by:
I have a string that has been saved in a database from a textarea form field. e.g. $text = "Dear %name The date is %date yours,
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.