ereg_replace replaces to mutch

This is a discussion on ereg_replace replaces to mutch within the PHP Language forums, part of the PHP Programming Forums category; Hello, I use a javascript ticker in my header which contains the news in a array like that tickercontents[0]='...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-04-2003
Chris
 
Posts: n/a
Default 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


Reply With Quote
  #2 (permalink)  
Old 11-04-2003
Justin Koivisto
 
Posts: n/a
Default Re: ereg_replace replaces to mutch

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 - spam@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Reply With Quote
  #3 (permalink)  
Old 11-04-2003
ChronoFish
 
Posts: n/a
Default Re: ereg_replace replaces to mutch

Rather than using replace

"Chris" <cmohn@gmx.de> wrote in message
news:vqfsc84rd4u975@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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0