[PHP] str_replace problem

2004-10-20 Thread Chris Ditty
Hi all.  I'm trying to do a little code snippets page for a site I am
working on.  I figured it would be simple enough.  I would do a
str_replace and replace the various html codes with the ascii
eqivulant.  Unfortunately, it is not working as expected.  Can anyone
help with this?

This is what I am using.
$snippetCode = str_replace(\n, br, $snippet['snippetCode']);
$snippetCode = str_replace(, gt;, $snippetCode);
$snippetCode = str_replace(, lt;, $snippetCode);
$snippetCode = str_replace(, amp;, $snippetCode);

This is what is in $snippet['snippetCode'].
?pre? print_r($ArrayName); ?/pre?

This is what is showing on the web page.
?lt;gt;prelt;gt;? print_r($ArrayName); ?lt;gt;/prelt;gt;?

If anyone can help, it would be appreciated.  Also, if you have a
quick and dirty code colorer, I would appreciate that.

Thanks
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] str_replace problem

2004-10-20 Thread Silvio Porcellana
Chris Ditty wrote:
Hi all.  I'm trying to do a little code snippets page for a site I am
working on.  I figured it would be simple enough.  I would do a
str_replace and replace the various html codes with the ascii
eqivulant.  Unfortunately, it is not working as expected.  Can anyone
help with this?
What is that you are actually expecting?
This is what I am using.
$snippetCode = str_replace(\n, br, $snippet['snippetCode']);
nl2br() [http://php.libero.it/manual/en/function.nl2br.php]
$snippetCode = str_replace(, gt;, $snippetCode);
$snippetCode = str_replace(, lt;, $snippetCode);
$snippetCode = str_replace(, amp;, $snippetCode);
This is what is in $snippet['snippetCode'].
?pre? print_r($ArrayName); ?/pre?
This is what is showing on the web page.
?lt;gt;prelt;gt;? print_r($ArrayName); ?lt;gt;/prelt;gt;?
This is what you are asking PHP to do.
Actually - to achieve this - it would be better to use the 'htmlspecialchars()' function 
[http://php.libero.it/manual/en/function.htmlspecialchars.php]

Anyway, probably I didn't understand what you want from your code...
Cheers!
Silvio Porcellana
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] str_replace problem

2004-10-20 Thread Robin Vickery
On Wed, 20 Oct 2004 01:02:12 -0500, Chris Ditty [EMAIL PROTECTED] wrote:
 Hi all.  I'm trying to do a little code snippets page for a site I am
 working on.  I figured it would be simple enough.  I would do a
 str_replace and replace the various html codes with the ascii
 eqivulant.  Unfortunately, it is not working as expected.  Can anyone
 help with this?
 
 This is what I am using.
 $snippetCode = str_replace(\n, br, $snippet['snippetCode']);
 $snippetCode = str_replace(, gt;, $snippetCode);
 $snippetCode = str_replace(, lt;, $snippetCode);
 $snippetCode = str_replace(, amp;, $snippetCode);
 
 This is what is in $snippet['snippetCode'].
 ?pre? print_r($ArrayName); ?/pre?
 
 This is what is showing on the web page.
 ?lt;gt;prelt;gt;? print_r($ArrayName); ?lt;gt;/prelt;gt;?

Ok, first off there are builtin functions to do this kind of thing:

  http://www.php.net/htmlspecialchars 
  http://www.php.net/nl2br

Secondly, think about what your code is doing, and the order that it's
doing the replacements.

The first thing you're doing is replacing the newlines with br tags.

The second and third things you're doing will disable all the tags
including the br tags you've just inserted, by replacing '' with
lt; and ' with gt html entities;

The fourth thing you're doing is disabling the html entities by
replacing '' with amp; including the entities you've just inserted
as steps two and three.

  -robin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] str_replace problem

2004-10-20 Thread Philip Thompson
On Oct 20, 2004, at 1:02 AM, Chris Ditty wrote:
Hi all.  I'm trying to do a little code snippets page for a site I am
working on.  I figured it would be simple enough.  I would do a
str_replace and replace the various html codes with the ascii
eqivulant.  Unfortunately, it is not working as expected.  Can anyone
help with this?
This is what I am using.
$snippetCode = str_replace(\n, br, $snippet['snippetCode']);
$snippetCode = str_replace(, gt;, $snippetCode);
 is actually less than
$snippetCode = str_replace(, lt;, $snippetCode);
and  is greater than. Don't know if this makes a difference to you.
$snippetCode = str_replace(, amp;, $snippetCode);
This is what is in $snippet['snippetCode'].
?pre? print_r($ArrayName); ?/pre?
This is what is showing on the web page.
?lt;gt;prelt;gt;? print_r($ArrayName); ?lt;gt;/prelt;gt;?
If anyone can help, it would be appreciated.  Also, if you have a
quick and dirty code colorer, I would appreciate that.
Thanks
Chris
Like the others have said, consider using htmlspecialchars().
Have fun!
~Philip
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] str_replace problem

2004-10-20 Thread Chris Ditty
Thanks all for the tips.  Was able to get it working like I wanted.

Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] str_replace() problem in PHP5 - anyone else?

2004-08-04 Thread Jon Bertsch
Hi all,
I have found a problem using the str_replace() function in PHP5. Over this 
past weekend we switched our production server to php5.0.0 running on 
apache 1.3.31 on SUSE9.1. Our development environment is identical. I have 
an application that runs a series of str_replace calls to drop in some 
document title and link information into an html string before sending it 
to the browser.

Code example:
$html_string[0] = lia 
href=\read_docs.php?file=@@FISCAL_YEAR@@/@@month@@/393_@@TYPE@@.pdftype=pdfaction=read\GEP 
amp; HIP Balances (GLC393)/a/li ;

$html_output_1 .= $html_string[0];
$output = str_replace(@@FISCAL_YEAR@@, $this_year, $html_output_1 );
(I call it three times to do the replacements in the string).
This basically produces a list of documents with links to there location 
from a database call.

On our development box this little application runs fine. In production 
where our server is getting around 1 million hits a day (but the processor 
is rarely above 1% usage) this function completely fails. The page just 
doesn't get shown. If I comment out the calls to str_replace the html goes 
over perfectly with the @@TOKEN@@ instead of the necessary information. If 
I change the str_replace to say YEAR or FISCAL etc it makes no difference.

I dropped the production server to php 4.3.8 and the str_replace() function 
works exactly as expected and there are no problems loading the page. Bump 
back to php5.0.0 and it coughs again.

Has anyone else seen anything like this or does anyone have an explanation? 
I can recode the series of str_replace calls but now I'm somewhat worried 
that other solutions will also fail.

It seems to me like there's maybe a load tolerance bug in php5 when running 
str_replace() since I can't see this on our development box nor in 4.3.8.

The only difference in the functions between php4 and 5 is the addition of 
the count option, could that be the issue?

Any help or comments would be greatly appreciated.
Thanks
Jon Bertsch
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] str_replace() problem in PHP5 - anyone else?

2004-08-04 Thread Jason Davidson
is it possbile $this-year isnt what you expect? 
Jason

Jon Bertsch [EMAIL PROTECTED] wrote: 
 
 
 Hi all,
 
 I have found a problem using the str_replace() function in PHP5. Over this 
 past weekend we switched our production server to php5.0.0 running on 
 apache 1.3.31 on SUSE9.1. Our development environment is identical. I have 
 an application that runs a series of str_replace calls to drop in some 
 document title and link information into an html string before sending it 
 to the browser.
 
 Code example:
 $html_string[0] = lia 
 href=\read_docs.php?file=@@FISCAL_YEAR@@/@@month@@/393_@@TYPE@@.pdftype=pdfaction=read\GEP
 
  HIP Balances (GLC393)/a/li ;
 
 $html_output_1 .= $html_string[0];
 
 $output = str_replace(@@FISCAL_YEAR@@, $this_year, $html_output_1 );
 
 (I call it three times to do the replacements in the string).
 
 This basically produces a list of documents with links to there location 
 from a database call.
 
 On our development box this little application runs fine. In production 
 where our server is getting around 1 million hits a day (but the processor 
 is rarely above 1% usage) this function completely fails. The page just 
 doesn't get shown. If I comment out the calls to str_replace the html goes 
 over perfectly with the @@TOKEN@@ instead of the necessary information. If 
 I change the str_replace to say YEAR or FISCAL etc it makes no difference.
 
 I dropped the production server to php 4.3.8 and the str_replace() function 
 works exactly as expected and there are no problems loading the page. Bump 
 back to php5.0.0 and it coughs again.
 
 Has anyone else seen anything like this or does anyone have an explanation? 
 I can recode the series of str_replace calls but now I'm somewhat worried 
 that other solutions will also fail.
 
 It seems to me like there's maybe a load tolerance bug in php5 when running 
 str_replace() since I can't see this on our development box nor in 4.3.8.
 
 The only difference in the functions between php4 and 5 is the addition of 
 the count option, could that be the issue?
 
 Any help or comments would be greatly appreciated.
 
 Thanks
 
 Jon Bertsch
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] str_replace() problem in PHP5 - anyone else?

2004-08-04 Thread Jon Bertsch

Jason wrote:
is it possbile $this-year isnt what you expect?
If I hard code the value it makes no difference and it works fine 
in  php4.3.x and in dev just not on php5  with some load on the server. It 
was tested on the same server before moving to live production and it 
worked then as well.

Jon Bertsch
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] str_replace() problem in PHP5 - anyone else?

2004-08-04 Thread Jason Davidson
Yup, i understand not in php 5, there was some large OO changes in php
5, which is why i asked about $this-year. Ive been using php 5 for the
last year, and havent had a problem with str_replace, and have used it a
fair amount for loading email templates.   
So when you look at the source, the @@FISCAL_YERAR@@ is still in the
html lines?  str_replace did not do anything at all?

Jason

Jon Bertsch [EMAIL PROTECTED] wrote: 
 
 
 
 Jason wrote:
  is it possbile $this-year isnt what you expect?
 
 If I hard code the value it makes no difference and it works fine 
 in  php4.3.x and in dev just not on php5  with some load on the server. It 
 was tested on the same server before moving to live production and it 
 worked then as well.
 
 Jon Bertsch
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] str_replace() problem in PHP5 - anyone else?

2004-08-04 Thread Jon Bertsch
Jason,
This code is not using any OO the variable is $this_year  not $this-year.
Running it under php5 on my dev box the string replace function works and 
replaces the text as expected.

Jon Bertsch
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] str_replace() problem in PHP5 - anyone else?

2004-08-04 Thread Jason Davidson
My mistake on $this_year.  


Jon Bertsch [EMAIL PROTECTED] wrote: 
 
 
 Jason,
 
 This code is not using any OO the variable is $this_year  not $this-year.
 
 Running it under php5 on my dev box the string replace function works and 
 replaces the text as expected.
 
 Jon Bertsch
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] str_replace() problem in PHP5 - anyone else?

2004-08-04 Thread Curt Zirzow
* Thus wrote Jon Bertsch:
 ...
 
 $html_output_1 .= $html_string[0];
 
 $output = str_replace(@@FISCAL_YEAR@@, $this_year, $html_output_1 );
 
 (I call it three times to do the replacements in the string).
 
 ...
 
 On our development box this little application runs fine. In production 
 where our server is getting around 1 million hits a day (but the processor 
 is rarely above 1% usage) this function completely fails. The page just 
 doesn't get shown. If I comment out the calls to str_replace the html goes 
 over perfectly with the @@TOKEN@@ instead of the necessary information. If 
 I change the str_replace to say YEAR or FISCAL etc it makes no difference.

I'd wager that your script is dying because your probably running
out of memory that php is allowed to use:

 - Check the local value of php.ini:memory_limit
 - set error_reporting = E_ALL
 - ensure log_errors is on and check the logs
   or turn display_errors on


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] str_replace() problem in PHP5 - anyone else?

2004-08-04 Thread Jon Bertsch
Jason,
Thanks for looking.
Very perplexing (to me at least).
Jon Bertsch
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] str_replace() problem in PHP5 - anyone else?

2004-08-04 Thread Justin Patrin
On Wed, 04 Aug 2004 08:14:55 -0700, Jon Bertsch [EMAIL PROTECTED] wrote:
 
 Hi all,
 
 I have found a problem using the str_replace() function in PHP5. Over this
 past weekend we switched our production server to php5.0.0 running on
 apache 1.3.31 on SUSE9.1. Our development environment is identical. I have
 an application that runs a series of str_replace calls to drop in some
 document title and link information into an html string before sending it
 to the browser.
 
 Code example:
 $html_string[0] = lia
 href=\read_docs.php?file=@@FISCAL_YEAR@@/@@month@@/393_@@TYPE@@.pdftype=pdfaction=read\GEP
 amp; HIP Balances (GLC393)/a/li ;
 
 $html_output_1 .= $html_string[0];
 
 $output = str_replace(@@FISCAL_YEAR@@, $this_year, $html_output_1 );
 
 (I call it three times to do the replacements in the string).
 
 This basically produces a list of documents with links to there location
 from a database call.
 
 On our development box this little application runs fine. In production
 where our server is getting around 1 million hits a day (but the processor
 is rarely above 1% usage) this function completely fails. The page just
 doesn't get shown. If I comment out the calls to str_replace the html goes
 over perfectly with the @@TOKEN@@ instead of the necessary information. If
 I change the str_replace to say YEAR or FISCAL etc it makes no difference.
 
 I dropped the production server to php 4.3.8 and the str_replace() function
 works exactly as expected and there are no problems loading the page. Bump
 back to php5.0.0 and it coughs again.
 
 Has anyone else seen anything like this or does anyone have an explanation?
 I can recode the series of str_replace calls but now I'm somewhat worried
 that other solutions will also fail.
 
 It seems to me like there's maybe a load tolerance bug in php5 when running
 str_replace() since I can't see this on our development box nor in 4.3.8.
 
 The only difference in the functions between php4 and 5 is the addition of
 the count option, could that be the issue?
 
 Any help or comments would be greatly appreciated.
 

Sounds like a threading issue to me. PHP and Apache 2 don't always get
along unless you're using Apache2 in prefork mode. These things
usually don't show up except under heavy load (which it seems you
have). Check out the link below for more info:

https://www.reversefold.com/tikiwiki/tiki-index.php?page=PHPFAQs#id45260

-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] str_replace problem

2004-03-17 Thread Labunski
Probleema sekojosha:
Shiim koda rindinjaam buutu jaanolasa IP adrese no temp.txt faila,
tad ieksh log.txt faila jaasameklee identiska IP adrese (taada pati kaa
temp.txt failaa)
un jaaizdzçð taa no log.txt faila.
Itkaa jau vienkaarshi, BET tas skripts nedarbojas :(

The problem is that str_replace isn't working preperly:
The whole idea of the script (below) is that it reads the IP address from
the temp.txt file,
then looks for identical IP address in log.txt file and deletes this IP
address from the log.txt file.
P.S.
temp.txt file has only one IP address, but log.txt file has many different
IP addresses.


$connect_temp_ip = fopen('temp.txt','r');
$temp_ip = fread($connect_temp_ip,filesize('temp.txt'));
fclose($connect_temp_ip);

$connect_log = fopen('log.txt','a+');
$empty = fread($connect_log,filesize('log.txt'));
$empty = str_replace($temp_ip,,$empty);
fwrite($connect_log, $empty);
fclose($connect_log);


Thank you very much,
Lab.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] str_replace problem

2004-03-17 Thread Jason Wong
On Wednesday 17 March 2004 20:16, Labunski wrote:

 The problem is that str_replace isn't working preperly:

So *how* does it not work properly?

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
If you ever want to get anywhere in politics, my boy, you're going to
have to get a toehold in the public eye.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] str_replace() problem

2003-03-31 Thread René Fournier
I am performing a str_replace() on a large string, and everything works 
fine, except that two of the elements I'm searching for (and replacing) 
have the same first letters. To keep it the issue clear, here's a 
simple example of what I'm talking about:

Blue
Blueberry
Now, if I use:

str_replace(Blue,Red,$paragraph);
str_replace(Blueberry,Strawberry,$paragraph);
...all occurrences of Blueincluding Blueberrywill be replaced with 
Red. The result will be something like:

Red
Redberry
...But what I want is...

Red
Strawberry
 I need str_replace to somehow only search for a complete occurrence of 
each item. How do I do that? I've read the docs, and I just can't see 
any examples.

Thanks.

...Rene

---
Ren Fournier,
[EMAIL PROTECTED]
Toll-free +1.888.886.2754
Tel +1.403.291.3601
Fax +1.403.250.5228
www.smartslitters.com
SmartSlitters International
#33, 1339 - 40th Ave NE
Calgary AB  T2E 8N6
Canada
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] str_replace() problem

2003-03-31 Thread Kevin Stone

- Original Message -
From: Ren Fournier [EMAIL PROTECTED]
To: php [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 1:52 PM
Subject: [PHP] str_replace() problem


 I am performing a str_replace() on a large string, and everything works
 fine, except that two of the elements I'm searching for (and replacing)
 have the same first letters. To keep it the issue clear, here's a
 simple example of what I'm talking about:

 Blue
 Blueberry

 Now, if I use:

 str_replace(Blue,Red,$paragraph);
 str_replace(Blueberry,Strawberry,$paragraph);


 ...all occurrences of Blueincluding Blueberrywill be replaced with
 Red. The result will be something like:

 Red
 Redberry

 ...But what I want is...

 Red
 Strawberry

   I need str_replace to somehow only search for a complete occurrence of
 each item. How do I do that? I've read the docs, and I just can't see
 any examples.

 Thanks.

 ...Rene

 ---
 Ren Fournier,
 [EMAIL PROTECTED]

You might be able to be more precise using ereg_replace().  But I donot know
the regular expression to make it happen.  Or if your situation allows it
you can hack it by appending a single space on the end of each input.
Either way what you need to do is give the script more information about
exactly what you want to replace.

echo str_replace(Blue , Red , $paragraph);

HTH,
Kevin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] str_replace() problem

2003-03-31 Thread Johnson, Kirk
You could replace the longer one, Blueberry, first. Then, the only
remaining occurrences of Blue will be ones that you really want.

Kirk

 I am performing a str_replace() on a large string, and 
 everything works 
 fine, except that two of the elements I'm searching for (and 
 replacing) 
 have the same first letters. To keep it the issue clear, here's a 
 simple example of what I'm talking about:
 
 Blue
 Blueberry
 
 Now, if I use:
 
 str_replace(Blue,Red,$paragraph);
 str_replace(Blueberry,Strawberry,$paragraph);
 
 
 ...all occurrences of Blueincluding Blueberrywill be replaced with 
 Red. The result will be something like:
 
 Red
 Redberry
 
 ...But what I want is...
 
 Red
 Strawberry

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] str_replace() problem

2003-03-31 Thread Marcus Rasmussen
Just change the order and do the search and replace on Blueberry before doing it 
on Blue.

Ei:

str_replace(Blueberry,Strawberry,$paragraph);
str_replace(Blue,Red,$paragraph);

or:

str_replace(array(Blueberry, Blue), array(Strawberry, Red), $paragraph);

_
Marcus Rasmussen
[EMAIL PROTECTED]
www.marcusr.dk

-
On 31-03-2003 at 13:52 René Fournier wrote:
-

I am performing a str_replace() on a large string, and everything works
fine, except that two of the elements I'm searching for (and replacing)
have the same first letters. To keep it the issue clear, here's a
simple example of what I'm talking about:

Blue
Blueberry

Now, if I use:

str_replace(Blue,Red,$paragraph);
str_replace(Blueberry,Strawberry,$paragraph);


...all occurrences of Blue—including Blueberry—will be replaced with
Red. The result will be something like:

Red
Redberry

...But what I want is...

Red
Strawberry

  I need str_replace to somehow only search for a complete occurrence of
each item. How do I do that? I've read the docs, and I just can't see
any examples.

Thanks.

...Rene

---
René Fournier,
[EMAIL PROTECTED]

Toll-free +1.888.886.2754
Tel +1.403.291.3601
Fax +1.403.250.5228
www.smartslitters.com

SmartSlitters International
#33, 1339 - 40th Ave NE
Calgary AB  T2E 8N6
Canada


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] str_replace problem

2002-02-04 Thread Tomy Wagner

hi, 

got a weird problem... what i am trying is this:
$str = str_replace(é, e, $str);
in a string containing a 'é' for sure...
but it doesn't replace it..
when i try this: 

echo str_replace(é, e, dfsdfsdfé);
it works !?

any suggestions?

Tomy Wagner