Ask a Question related to PHP Development, Design and Development.
-
Chris #1
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
Chris Guest
-
Contribute replaces ? with %3F when creating a link...
Hello, This problem occurs sometimes and we couldn't find out why it happenes. When creating a link we chose the destination php file and add... -
extension that searches for certain characters and replaces them
Hey, I am trying to develop a new extension for dwmx which searches for certain characters and replaces them with other characters! How do I go... -
ereg_replace
> $linked_comments = ereg_replace("\n","<br>",$linked_comments"); Try: $linked_comments = str_replace("\r\n","\n",$linked_comments");... -
Can xml replaces a server technology
If that is the case, can I use xml in conjunction with asp? Or, is there a way to make vbscript compatible to browser other than IE. I ask this... -
Justin Koivisto #2
Re: ereg_replace replaces to mutch
Chris wrote:
> ereg_replace("(tickercontents\[0\]\=)(')(.*)(')","\\1\\2$ersatz\\4",$file1)Try:> 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
preg_replace("/tickercontents\[0\]='([^']*)'/iU","tickercontents[0]='$ersatz'",$file1);
--
Justin Koivisto - [email]spam@koivi.com[/email]
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Justin Koivisto Guest
-
ChronoFish #3
Re: ereg_replace replaces to mutch
Rather than using replace
"Chris" <cmohn@gmx.de> wrote in message
news:vqfsc84rd4u975@corp.supernews.com...ereg_replace("(tickercontents\[0\]\=)(')(.*)(')","\\1\\2$ersatz\\4",$file1)> 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 =
>> 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
ChronoFish Guest



Reply With Quote

