By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,730 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,730 IT Pros & Developers. It's quick & easy.

str_replace

P: n/a
Hello,

Replacing the key : #0001# within $data doesn't work!! I want to replace it
with a link!

Any sugestions?

Thanx,
InSeCo

*Example of the problem :*
<?php
$data = "abcdefghijklmnopqrstuvwxyz #0001# abcdefghijklmnopqrstuvwxyz<BR>
\n";
$data = $data."abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz<BR>
\n";
$data = $data."abcdefghijklmnopqrstuvwxyz #0001#
abcdefghijklmnopqrstuvwxyz<BR> \n";

$repldata = "<A href=link.html>link</a>";
$replold = "#0001#";
echo "<B>Original Data</B><BR>$data;<HR>";
echo "<B>Data to replace :</B> $replold <HR>";
echo "<B>Replace data with :</B> $repldata <HR>";

str_replace($replold, $repldata , $data);
echo "<B>New Data</B><BR>$data;<HR>";

?>
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"InSeCo" <In****@news.news> kirjoitti
viestissä:42*********************@news.xs4all.nl.. .
Hello,

Replacing the key : #0001# within $data doesn't work!! I want to replace
it
with a link!

Any sugestions?

Thanx,
InSeCo

*Example of the problem :*
<?php
$data = "abcdefghijklmnopqrstuvwxyz #0001# abcdefghijklmnopqrstuvwxyz<BR>
\n";
$data = $data."abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz<BR>
\n";
$data = $data."abcdefghijklmnopqrstuvwxyz #0001#
abcdefghijklmnopqrstuvwxyz<BR> \n";

$repldata = "<A href=link.html>link</a>";
$replold = "#0001#";
echo "<B>Original Data</B><BR>$data;<HR>";
echo "<B>Data to replace :</B> $replold <HR>";
echo "<B>Replace data with :</B> $repldata <HR>";
$data = str_replace($replold, $repldata , $data); // fix this echo "<B>New Data</B><BR>$data;<HR>";

?>


It doesn't perform the change on parameter given, instead it returns the
changed string. Surely, it must've done what you wanted using $data as
input, but your code just didn't assign the returned value to $data.
Jul 17 '05 #2

P: n/a
InSeCo wrote:
str_replace($replold, $repldata , $data);


Perhaps it worked a bit better if you stored the result of str_replace()
somewhere?

Just wondering :)

--
Markku Uttula
Jul 17 '05 #3

P: n/a
How do I store the result somewhere else??
"Markku Uttula" <ma***********@disconova.com> wrote in message
news:Vs****************@reader1.news.jippii.net...
InSeCo wrote:
str_replace($replold, $repldata , $data);


Perhaps it worked a bit better if you stored the result of str_replace()
somewhere?

Just wondering :)

--
Markku Uttula

Jul 17 '05 #4

P: n/a
InSeCo wrote:
str_replace($replold, $repldata , $data);


Perhaps it worked a bit better if you stored the result of
str_replace() somewhere?


How do I store the result somewhere else??


$data = str_replace($replold, $repldata , $data);

Please, read the manual. It has some great examples.
--
Markku Uttula
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.