Re: [PHP] str_replace around a character??

2011-07-13 Thread Jay Ess

On 2011-07-13 09:54, Karl DeSaulniers wrote:


$cc = ema...@domain.com ,ema...@doamin.com,ema...@domain.com , 
ema...@domain.com,  


$cc = trim($cc,,);
$result = preg_replace('/(\s?)(,)(\s?)/i', ',', $cc);


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



Re: [PHP] str_replace around a character??

2011-07-13 Thread Vitalii Demianets
On Wednesday 13 July 2011 11:09:45 Jay Ess wrote:
 On 2011-07-13 09:54, Karl DeSaulniers wrote:
  $cc = ema...@domain.com ,ema...@doamin.com,ema...@domain.com ,
  ema...@domain.com, 

 $cc = trim($cc,,);
 $result = preg_replace('/(\s?)(,)(\s?)/i', ',', $cc);

The solution is broken because of:
1) you have missed spaces after comma in two places. It should be like this:
$cc = trim($cc,, ); // - here space after comma in the second argument
$result = preg_replace('/(\s?)(,)(\s?)/i', ', ', $cc); // -- the same, here 
space after comma in replacement string.

2) it doesn't work with address lines like this:

To: Some   strange ,, person name strper...@example.com

-- 
Vitalii

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



Re: [PHP] str_replace around a character??

2011-07-13 Thread Jay Ess

On 2011-07-13 10:36, Vitalii Demianets wrote:

On Wednesday 13 July 2011 11:09:45 Jay Ess wrote:

On 2011-07-13 09:54, Karl DeSaulniers wrote:

$cc = ema...@domain.com ,ema...@doamin.com,ema...@domain.com ,
ema...@domain.com, 

$cc = trim($cc,,);
$result = preg_replace('/(\s?)(,)(\s?)/i', ',', $cc);

The solution is broken because of:
1) you have missed spaces after comma in two places. It should be like this:
$cc = trim($cc,, ); //- here space after comma in the second argument
$result = preg_replace('/(\s?)(,)(\s?)/i', ', ', $cc); //-- the same, here
space after comma in replacement string.

Yes, that was pretty sloppy of me hehe.


2) it doesn't work with address lines like this:

To: Some   strange ,, person namestrper...@example.com

That was never the requirement ;)

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



Re: [PHP] str_replace around a character??

2011-07-13 Thread Shiplu Mokaddim
 If you are looking for a one liner reg ex, it may take some time. This may 
lead wasting your development time. Better you do the following,

1. replace the string with tokens in address.
2. Split using comma.
3. Apply common email regex.
4. Replace tokens with actual strings.
5. Rebuild/join the string with , 

With this approach you can validate individual emails too.


Sent from a handheld device


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



Re: [PHP] str_replace

2011-04-25 Thread Jim Lucas
On 4/24/2011 8:44 AM, Ron Piggott wrote:
 
 I am trying to figure out a syntax that will replace each instance of % with a
 different letter chosen randomly from the string $puzzle_filler. 
 $puzzle_filler
 is populated with the letters of the alphabet, roughly in the same ratio as 
 they
 are used.
 
 This syntax replaces each instance of % with the same letter:
 
 $puzzle[$i] = str_replace ( % , ( substr ( $puzzle_filler , rand(1,98) , 1 
 ) )
 , $puzzle[$i] );
 
 Turning this:
 
 %ECARBME%TIPLUP%%%E%%
 
 Into:
 
 uECARBMEuTIPLUPuuuEuu
 
 Is there a way to tweak my str_replace so it will only do 1 % at a time, so a
 different replacement letter is selected?
 
 This is the syntax specific to choosing a replacement letter at random:
 
 substr ( $puzzle_filler , rand(1,98) , 1 );
 
 Thanks for your help.
 
 Ron
 
 The Verse of the Day
 “Encouragement from God’s Word”
 http://www.TheVerseOfTheDay.info
 

How about something simple like this?

?php

$input = '%ECARBME%TIPLUP%%%E%%';

$random_chars = range('a', 'z');

echo 'Before: '.$input.PHP_EOL;

while ( ($pos = strpos($input, '%') ) !== false )
$input[$pos] = $random_chars[array_rand($random_chars)];

echo 'After: '.$input.PHP_EOL;

?


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



Re: [PHP] str_replace

2011-04-25 Thread Nathan Rixham

Jim Lucas wrote:

On 4/24/2011 8:44 AM, Ron Piggott wrote:

I am trying to figure out a syntax that will replace each instance of % with a
different letter chosen randomly from the string $puzzle_filler. $puzzle_filler
is populated with the letters of the alphabet, roughly in the same ratio as they
are used.

This syntax replaces each instance of % with the same letter:

$puzzle[$i] = str_replace ( % , ( substr ( $puzzle_filler , rand(1,98) , 1 ) )
, $puzzle[$i] );

Turning this:

%ECARBME%TIPLUP%%%E%%

Into:

uECARBMEuTIPLUPuuuEuu

Is there a way to tweak my str_replace so it will only do 1 % at a time, so a
different replacement letter is selected?

This is the syntax specific to choosing a replacement letter at random:

substr ( $puzzle_filler , rand(1,98) , 1 );

Thanks for your help.

Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info



How about something simple like this?

?php

$input = '%ECARBME%TIPLUP%%%E%%';

$random_chars = range('a', 'z');

echo 'Before: '.$input.PHP_EOL;

while ( ($pos = strpos($input, '%') ) !== false )
$input[$pos] = $random_chars[array_rand($random_chars)];

echo 'After: '.$input.PHP_EOL;


just for fun

$a = '%ECARBME%TIPLUP%%%E%%';
$b = 'abcdefghijklmnobqrstuvwxyz';
echo preg_replace('/%/e','substr(str_shuffle($b),-1)', $a );

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



Re: [PHP] str_replace

2011-04-24 Thread Daniel Brown
On Sun, Apr 24, 2011 at 11:44, Ron Piggott
ron.pigg...@actsministries.org wrote:

 I am trying to figure out a syntax that will replace each instance of % with
 a different letter chosen randomly from the string $puzzle_filler.
 $puzzle_filler is populated with the letters of the alphabet, roughly in the
 same ratio as they are used.

 This syntax replaces each instance of % with the same letter:

 $puzzle[$i] = str_replace ( % , ( substr ( $puzzle_filler , rand(1,98) , 1
 ) ) , $puzzle[$i] );

 Turning this:

 %ECARBME%TIPLUP%%%E%%

 Into:

 uECARBMEuTIPLUPuuuEuu

 Is there a way to tweak my str_replace so it will only do 1 % at a time, so
 a different replacement letter is selected?

 This is the syntax specific to choosing a replacement letter at random:

 substr ( $puzzle_filler , rand(1,98) , 1 );

I just mocked this up now, and only tested it twice.  It's not the
most elegant solution, and probably shouldn't be used in high-demand
situations, but it should at least serve to get you started.

?php

$str = '%ECARBME%TIPLUP%%%E%%';
$chars = 'abcdefghijklmnopqrstuvwxyz';

echo multi_replace($str,'%',$chars).PHP_EOL; // Case-sensitive,
random, straight replace
echo multi_replace($str,'%',$chars,0,1,1).PHP_EOL; //
Case-insensitive, random, randomg casing

function 
multi_replace($str,$targ,$chars,$sens=true,$random=true,$caserand=false)
{

// Loop through while $targ is still found in $str
while (strstr($str,$targ) !== false) {

// If we're randomizing, pick the character; else the
first (or only)
if ($random == true  !is_null($random)) {
$replace = $chars[mt_rand(0,(strlen($chars) - 1))];
} else {
$replace = substr($chars,0,1);
}

// If we want random casing, do that; else make no change
if ($caserand == true  !is_null($caserand)) {
if (mt_rand(0,1) === 0) {
$replace = strtolower($replace);
} else {
$replace = strtoupper($replace);
}
}

// If we don't want case sensitivity, set the regexp modifier
$mod = $sens == false || is_null($sens) ? 'i' : '';

// Perform the match and replace only one character now
$str = preg_replace('/'.$targ.'/U'.$mod,$replace,$str,1);

} // End of loop

// Return the modified string
return $str;
}
?

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

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



Re: [PHP] str_replace

2011-04-24 Thread Daniel Brown
On Sun, Apr 24, 2011 at 12:33, Daniel Brown danbr...@php.net wrote:

    I just mocked this up now, and only tested it twice.  It's not the
 most elegant solution, and probably shouldn't be used in high-demand
 situations, but it should at least serve to get you started.

And since email wrecks code formatting, it's also up here:

http://links.parasane.net/nth2

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

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



Re: [PHP] str_replace

2011-04-24 Thread Adam Richardson
On Sun, Apr 24, 2011 at 11:44 AM, Ron Piggott 
ron.pigg...@actsministries.org wrote:


 I am trying to figure out a syntax that will replace each instance of %
 with a different letter chosen randomly from the string $puzzle_filler.
 $puzzle_filler is populated with the letters of the alphabet, roughly in the
 same ratio as they are used.

 This syntax replaces each instance of % with the same letter:

 $puzzle[$i] = str_replace ( % , ( substr ( $puzzle_filler , rand(1,98) ,
 1 ) ) , $puzzle[$i] );

 Turning this:

 %ECARBME%TIPLUP%%%E%%

 Into:

 uECARBMEuTIPLUPuuuEuu

 Is there a way to tweak my str_replace so it will only do 1 % at a time, so
 a different replacement letter is selected?

 This is the syntax specific to choosing a replacement letter at random:

 substr ( $puzzle_filler , rand(1,98) , 1 );

 Thanks for your help.

 Ron

 The Verse of the Day
 “Encouragement from God’s Word”
 http://www.TheVerseOfTheDay.info

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


Quick guess trying to be fairly performant:

function fill_puzzle($puzzle, $puzzle_filler) {
$puzzle_length = strlen($puzzle);
$puzzle_filler_length = strlen($puzzle_filler);
 for ($i = 0; $i  $puzzle_length; $i++) {
if ($puzzle[$i] == '%') {
$puzzle[$i] = $puzzle_filler[mt_rand(0, ($puzzle_filler_length - 1))];
}
}
 return $puzzle;
}

echo fill_puzzle($puzzle = %ECARBME%TIPLUP%%%E%%, $puzzle_filler =
ABCDEFGHIJKLMNOPQRSTUVWXYZ);

Happy Easter :)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] str_replace

2011-04-24 Thread Stuart Dallas
On Sunday, 24 April 2011 at 16:44, Ron Piggott wrote:

 I am trying to figure out a syntax that will replace each instance of % with 
 a different letter chosen randomly from the string $puzzle_filler. 
 $puzzle_filler is populated with the letters of the alphabet, roughly in the 
 same ratio as they are used.
 
 This syntax replaces each instance of % with the same letter:
 
 $puzzle[$i] = str_replace ( % , ( substr ( $puzzle_filler , rand(1,98) , 
 1 ) ) , $puzzle[$i] );
 
 Turning this:
 
 %ECARBME%TIPLUP%%%E%%
 
 Into:
 
 uECARBMEuTIPLUPuuuEuu
 
 Is there a way to tweak my str_replace so it will only do 1 % at a time, so 
 a different replacement letter is selected?
 
 This is the syntax specific to choosing a replacement letter at random:
 
 substr ( $puzzle_filler , rand(1,98) , 1 );
 
 Thanks for your help.

I would probably go with http://php.net/preg_replace_callback

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/





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



Re: [PHP] str_replace

2011-04-24 Thread Richard Quadling
On 24 April 2011 16:44, Ron Piggott ron.pigg...@actsministries.org wrote:

 I am trying to figure out a syntax that will replace each instance of % with
 a different letter chosen randomly from the string $puzzle_filler.
 $puzzle_filler is populated with the letters of the alphabet, roughly in the
 same ratio as they are used.

 This syntax replaces each instance of % with the same letter:

 $puzzle[$i] = str_replace ( % , ( substr ( $puzzle_filler , rand(1,98) , 1
 ) ) , $puzzle[$i] );

 Turning this:

 %ECARBME%TIPLUP%%%E%%

 Into:

 uECARBMEuTIPLUPuuuEuu

 Is there a way to tweak my str_replace so it will only do 1 % at a time, so
 a different replacement letter is selected?

 This is the syntax specific to choosing a replacement letter at random:

 substr ( $puzzle_filler , rand(1,98) , 1 );

 Thanks for your help.

 Ron

 The Verse of the Day
 “Encouragement from God’s Word”
 http://www.TheVerseOfTheDay.info

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



Something like this ...

?php
$s_Text = '%ECARBME%TIPLUP%%%E%%';
$s_PuzzleFilter = '0123456789';
echo preg_replace_callback(
  '`%`',
  function() use($s_PuzzleFilter) {
return substr($s_PuzzleFilter, mt_rand(0, strlen($s_PuzzleFilter)
- 1), 1);},
  $s_Text
);


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] str_replace help

2010-04-02 Thread Ashley Sheridan
On Fri, 2010-04-02 at 09:28 -0400, David Stoltz wrote:

 Hi folks,
  
 In ASP, I would commonly replace string line feeds for HTML output like
 this:
  
 Var = replace(value,vbcrlf,br)
  
 In PHP, the following doesn't seem to work:
 $var = str_replace(chr(13),\n,$value)
  
 Neither does:
 $var = str_replace(chr(10),\n,$value)
  
 What am I doing wrong?
  
 Thanks!


I see no reason why it shouldn't work other than maybe the string
doesn't contain what you think it does.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] str_replace help

2010-04-02 Thread Midhun Girish
well david actually $var = str_replace(chr(13),\n,$value) will replace
char(13) with \n... but \n wont come up in html unless u give a pre tag..
u need to put

$var = str_replace(chr(13),br/,$value) in order to got the required
output


Midhun Girish


On Fri, Apr 2, 2010 at 7:03 PM, Ashley Sheridan 
a...@ashleysheridan.co.ukwrote:

 On Fri, 2010-04-02 at 09:28 -0400, David Stoltz wrote:

  Hi folks,
 
  In ASP, I would commonly replace string line feeds for HTML output like
  this:
 
  Var = replace(value,vbcrlf,br)
 
  In PHP, the following doesn't seem to work:
  $var = str_replace(chr(13),\n,$value)
 
  Neither does:
  $var = str_replace(chr(10),\n,$value)
 
  What am I doing wrong?
 
  Thanks!


 I see no reason why it shouldn't work other than maybe the string
 doesn't contain what you think it does.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Re: [PHP] str_replace help

2010-04-02 Thread Nilesh Govindarajan

On 04/02/10 18:58, David Stoltz wrote:

Hi folks,

In ASP, I would commonly replace string line feeds for HTML output like
this:

Var = replace(value,vbcrlf,br)

In PHP, the following doesn't seem to work:
$var = str_replace(chr(13),\n,$value)

Neither does:
$var = str_replace(chr(10),\n,$value)

What am I doing wrong?

Thanks!



Use nl2br.

--
Nilesh Govindarajan
Site  Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !

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



Re: [PHP] str_replace

2009-08-08 Thread LinuxManMikeC
On Sat, Aug 8, 2009 at 2:08 AM, Ron Piggottron@actsministries.org wrote:
 Am I understanding str_replace correctly?  Do I have this correct or are ' 
 needed?

 $bible_verse_ref is what I want to change to (AKA replace)
 bible_verse_ref is what I change to change from (AKA search)
 $text_message_template is the string I want to manipulate

 $text_message = str_replace( $bible_verse_ref, 'bible_verse_ref', 
 $text_message_template );

 Ron

If I understand you right, I think you have the search and replace
arguments mixed up.  Your current code will look for all occurrences
of $bible_verse_ref in $text_message_template and replace it with
'bible_verse_ref'.

http://us.php.net/manual/en/function.str-replace.php

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



Re: [PHP] str_replace

2009-08-08 Thread Ron Piggott


Yes I did.  Thank you for confirming this with me.  Ron

- Original Message - 
From: LinuxManMikeC linuxmanmi...@gmail.com

To: Ron Piggott ron@actsministries.org
Cc: php-general@lists.php.net; phps...@gmail.com
Sent: Saturday, August 08, 2009 6:19 AM
Subject: Re: [PHP] str_replace


On Sat, Aug 8, 2009 at 2:08 AM, Ron Piggottron@actsministries.org 
wrote:
Am I understanding str_replace correctly? Do I have this correct or are ' 
needed?


$bible_verse_ref is what I want to change to (AKA replace)
bible_verse_ref is what I change to change from (AKA search)
$text_message_template is the string I want to manipulate

$text_message = str_replace( $bible_verse_ref, 'bible_verse_ref', 
$text_message_template );


Ron


If I understand you right, I think you have the search and replace
arguments mixed up.  Your current code will look for all occurrences
of $bible_verse_ref in $text_message_template and replace it with
'bible_verse_ref'.

http://us.php.net/manual/en/function.str-replace.php






No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.392 / Virus Database: 270.13.47/2289 - Release Date: 08/07/09 
18:37:00



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



RE: [PHP] str_replace oddity

2007-09-23 Thread Peter Lauri
No, turn Magic Quotes off :)

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: Sunday, September 23, 2007 3:10 AM
 To: Jim Lucas
 Cc: Kevin Waterson; php-general@lists.php.net
 Subject: Re: [PHP] str_replace oddity
 
 So replace ' \ ' instead of '  '.
 
 On 9/22/07, Jim Lucas [EMAIL PROTECTED] wrote:
  Kevin Waterson wrote:
   I am using str_replace to strip double quotes.
  
   $string = 'This string has quotes in it';
  
   $string = str_replace('', '', $string);
  
   this seems to work, yet when I put the $string into mysql,
   it uses backslashes to escape where the quotes were. The
   double-quotes are gone, yet it still escapes the 'ghost'
   where they were.
  
   I even tried
   str_replace(array(\x8c, \x9c, ', ''), '', $string)
   but the ghost remains and mysql continues to escape them.
  
   I check the charsets, and the db is Latin-1 and the sting is ISO-8859-
 1
  
   Any thoughts on this would be most graciously accepted.
   Kind regards
   kevin
  
  
  is $string honestly something that you are getting via a form submit?
 
  if so, your system might have magic quotes enabled.
 
  This would automatically escape quotes with the attempt to make the
  values safer, and then you go and run your str_replace command and
  remove the double quotes, you end up leaving the '\' that the system
  automatically put in the value for you.
 
  read up on magic quote gpc
 
  hope this helps.
 
  Jim
 
  --
  Jim Lucas
 
 
   Perseverance is not a long race;
   it is many short races one after the other
 
  Walter Elliot
 
 
 
   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.
 
  Twelfth Night, Act II, Scene V
   by William Shakespeare
 
  --
  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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] str_replace oddity

2007-09-22 Thread Jim Lucas

Kevin Waterson wrote:

I am using str_replace to strip double quotes.

$string = 'This string has quotes in it';

$string = str_replace('', '', $string);

this seems to work, yet when I put the $string into mysql,
it uses backslashes to escape where the quotes were. The
double-quotes are gone, yet it still escapes the 'ghost'
where they were.

I even tried 
str_replace(array(\x8c, \x9c, ', ''), '', $string)

but the ghost remains and mysql continues to escape them.

I check the charsets, and the db is Latin-1 and the sting is ISO-8859-1

Any thoughts on this would be most graciously accepted.
Kind regards
kevin



is $string honestly something that you are getting via a form submit?

if so, your system might have magic quotes enabled.

This would automatically escape quotes with the attempt to make the 
values safer, and then you go and run your str_replace command and 
remove the double quotes, you end up leaving the '\' that the system 
automatically put in the value for you.


read up on magic quote gpc

hope this helps.

Jim

--
Jim Lucas


Perseverance is not a long race;
it is many short races one after the other

Walter Elliot



Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] str_replace oddity

2007-09-22 Thread heavyccasey
So replace ' \ ' instead of '  '.

On 9/22/07, Jim Lucas [EMAIL PROTECTED] wrote:
 Kevin Waterson wrote:
  I am using str_replace to strip double quotes.
 
  $string = 'This string has quotes in it';
 
  $string = str_replace('', '', $string);
 
  this seems to work, yet when I put the $string into mysql,
  it uses backslashes to escape where the quotes were. The
  double-quotes are gone, yet it still escapes the 'ghost'
  where they were.
 
  I even tried
  str_replace(array(\x8c, \x9c, ', ''), '', $string)
  but the ghost remains and mysql continues to escape them.
 
  I check the charsets, and the db is Latin-1 and the sting is ISO-8859-1
 
  Any thoughts on this would be most graciously accepted.
  Kind regards
  kevin
 
 
 is $string honestly something that you are getting via a form submit?

 if so, your system might have magic quotes enabled.

 This would automatically escape quotes with the attempt to make the
 values safer, and then you go and run your str_replace command and
 remove the double quotes, you end up leaving the '\' that the system
 automatically put in the value for you.

 read up on magic quote gpc

 hope this helps.

 Jim

 --
 Jim Lucas


  Perseverance is not a long race;
  it is many short races one after the other

 Walter Elliot



  Some men are born to greatness, some achieve greatness,
  and some have greatness thrust upon them.

 Twelfth Night, Act II, Scene V
  by William Shakespeare

 --
 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 new line

2007-07-02 Thread Greg Donald

On 6/30/07, jekillen [EMAIL PROTECTED] wrote:

Hello;
I have the following  code:

$prps = str_replace(\n, ' ', $input[3]);


Are you sure $input[3] doesn't have two newlines at the end?

Why not use trim() to be sure?


  $request = str_replace(// var purpose = {} ;\n, var purpose =
'$prps';\n, $request);

In the first line $input[3] is a string formatted with new lines at the
end of each line.
It is to be used to initialize a javascript variable (in the second
line above), in an html file
template.
When the html file is generated from the template, the javascript
written to it fails
with unterminated string literal error message.
When opening a view source window, the 'var purpose...' line does have
the string
broken up with extra spaces at the beginning of each line. This
indicates that
the new line was not replaced with the space. The space was merely
added after
the new line.
How do you replace a new line with php in a case like this?


Why do you want to replace it, you just said you wanted to remove it above?


Testing this is very tedious.


Do you use Firebug?  It's a Firefox extension.  Makes debugging
Javascript very easy.

Also you might try the 'view rendered source' extension.  Lets you
view the live DOM, not just the possibly outdated version of your html
the view source option gives.


Each time I have to go through and undo
file modifications that this function performs in addition to the above.
So it is not just a case of making a change and reloading the file
and rerunning it.


Brutal.  :(


--
Greg Donald
http://destiney.com/

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



Re: [PHP] str_replace new line

2007-07-02 Thread jekillen


On Jul 2, 2007, at 6:07 PM, jekillen wrote:



On Jul 2, 2007, at 3:15 PM, Greg Donald wrote:


On 6/30/07, jekillen [EMAIL PROTECTED] wrote:

Hello;
I have the following  code:

$prps = str_replace(\n, ' ', $input[3]);


Are you sure $input[3] doesn't have two newlines at the end?

Why not use trim() to be sure?


  $request = str_replace(// var purpose = {} ;\n, var purpose =
'$prps';\n, $request);

In the first line $input[3] is a string formatted with new lines at 
the

end of each line.
It is to be used to initialize a javascript variable (in the second
line above), in an html file
template.
When the html file is generated from the template, the javascript
written to it fails
with unterminated string literal error message.
When opening a view source window, the 'var purpose...' line does 
have

the string
broken up with extra spaces at the beginning of each line. This
indicates that
the new line was not replaced with the space. The space was merely
added after
the new line.
How do you replace a new line with php in a case like this?


Why do you want to replace it, you just said you wanted to remove it 
above?


So it will not cause javascript errors when written as a javascript 
variable value

The out put goes like this:
var string = 'this is some text(\n)
with a new line in the string.'
It cause a javascript unterminated string literal error because of the 
line break
caused by the new line. I need to replace the new lines with spaces so 
it is

one long string.
It is that simple, Please.


Do you use Firebug?  It's a Firefox extension.

I do not need to debug the javascript, It is the php which
is tedious to change and retest.  The php code writes
the javascript to an html file, So I need to change the php
or find another way.

Does anyone have a simple answer to a simple question?
I am trying to replace newlines in a string with spaces. The code
I posted originally is not working. Perhaps I am doing something
wrong in that code,
That is all I am asking.
JK



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



Re: [PHP] str_replace new line

2007-07-02 Thread Jim Lucas

jekillen wrote:


On Jul 2, 2007, at 6:07 PM, jekillen wrote:



On Jul 2, 2007, at 3:15 PM, Greg Donald wrote:


On 6/30/07, jekillen [EMAIL PROTECTED] wrote:

Hello;
I have the following  code:

$prps = str_replace(\n, ' ', $input[3]);


Are you sure $input[3] doesn't have two newlines at the end?

Why not use trim() to be sure?


  $request = str_replace(// var purpose = {} ;\n, var purpose =
'$prps';\n, $request);

In the first line $input[3] is a string formatted with new lines at the
end of each line.
It is to be used to initialize a javascript variable (in the second
line above), in an html file
template.
When the html file is generated from the template, the javascript
written to it fails
with unterminated string literal error message.
When opening a view source window, the 'var purpose...' line does have
the string
broken up with extra spaces at the beginning of each line. This
indicates that
the new line was not replaced with the space. The space was merely
added after
the new line.
How do you replace a new line with php in a case like this?


Why do you want to replace it, you just said you wanted to remove it 
above?


So it will not cause javascript errors when written as a javascript 
variable value

The out put goes like this:
var string = 'this is some text(\n)
with a new line in the string.'
It cause a javascript unterminated string literal error because of the 
line break
caused by the new line. I need to replace the new lines with spaces so 
it is

one long string.
It is that simple, Please.


Do you use Firebug?  It's a Firefox extension.

I do not need to debug the javascript, It is the php which
is tedious to change and retest.  The php code writes
the javascript to an html file, So I need to change the php
or find another way.

Does anyone have a simple answer to a simple question?
I am trying to replace newlines in a string with spaces. The code
I posted originally is not working. Perhaps I am doing something
wrong in that code,
That is all I am asking.
JK



$out = str_replace(\n, '\n', $in);

This will actually have a \n show in the javascript, so when it is 
printed/used by JS it will have a line feed in the output of JS.


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



Re: [PHP] str_replace new line

2007-07-02 Thread Richard Lynch
On Sat, June 30, 2007 12:04 pm, jekillen wrote:
 Hello;
 I have the following  code:

 $prps = str_replace(\n, ' ', $input[3]);
   $request = str_replace(// var purpose = {} ;\n, var purpose =
 '$prps';\n, $request);

 In the first line $input[3] is a string formatted with new lines at
 the
 end of each line.
 It is to be used to initialize a javascript variable (in the second
 line above), in an html file
 template.
 When the html file is generated from the template, the javascript
 written to it fails
 with unterminated string literal error message.
 When opening a view source window, the 'var purpose...' line does have
 the string
 broken up with extra spaces at the beginning of each line. This
 indicates that
 the new line was not replaced with the space. The space was merely
 added after
 the new line.
 How do you replace a new line with php in a case like this?

I don't know what you think you did, but I know that what you are
saying about \n not actually getting replaced is wrong...

 Testing this is very tedious. Each time I have to go through and undo
 file modifications that this function performs in addition to the
 above.
 So it is not just a case of making a change and reloading the file
 and rerunning it.

COPY the file before the mods, and just copy it back after.

Or change your code to just output what it's doing and not overwrite
the file for development.

Or...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] str_replace on words with an array

2006-11-04 Thread Dotan Cohen

On 03/11/06, Richard Lynch [EMAIL PROTECTED] wrote:

On Fri, November 3, 2006 5:30 am, Dotan Cohen wrote:
 To all others who took part in this thread: I was unclear on another
 point as well, the issue of sql-injection. As I'm removing the
 symbols, signs, and other non-alpha characters from the query, I
 expect it to be sql-injection proof. As I wrong? ie, could an attacker
 successful inject sql if he has nothing but alpha characters at his
 disposal? I think not, but I'd like to hear it from someone with more
 experience than i.

In Latin1, ISO-8891-1 or whatever, plain old not-quite-ASCII, yeah,
you should be safe, I think...

I'm making *no* promises if your DB is configured to accept some
*other* character set, or the Bad Guy manages to trick it into
thinking it should be using that charset.


Yep, configured to accept UTF-8. Us Hebrew-speakers and our funny letters :)


Why the big deal about just calling mysql_real_escape_string() on your
data?


No biggie- I'm doing that too.


Or using prepared statements and that ilk?

Then you'd be 100% sure, and not worrying about it, eh?


Well, abstinence is not an option! I can't use prepared statements on
a full-text search.

Thanks, Richard. When is that Uranus office opening I've been
waiting almost five years!!

Dotan Cohen

nirot.com
http://what-is-what.com/what_is/ubuntu.html

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



Re: [PHP] str_replace on words with an array

2006-11-03 Thread Dotan Cohen

On 31/10/06, Larry Garfield [EMAIL PROTECTED] wrote:

From your original message, it sounds like you want to strip selected complete
words, not substrings, from a string for indexing or searching or such.
Right?


I think that was my mistake- not differentiating between the two.
Symbols and such I wanted to replace as substrings, yet noise words I
wanted to replace as words. Now that I've created two arrays, one with
symbols and one with noise words, things are on track.


Try something like this:

$string = The quick sly fox jumped over a fence and ran away;
$words = array('the', 'a', 'and');

function make_regex($str) {
  return '/\b' . $str . '\b/i';
}

$search = array_map('make_regex', $words);
$string = preg_replace($search, '', $string);
print $string . \n;


I was completely unaware of the array_map function. Thank you- that is
exactly what I needed.


What you really need to do that is to match word boundaries, NOT string
boundaries.  So you take your list of words and mutate *each one* (that's
what the array_map() is about) into a regex pattern that finds that word,
case-insensitively.  Then you use preg_replace() to replace all matches of
any of those patterns with an empty string.


Yep.


You were close.  What you were missing was the array_map(), because you needed
to concatenate stuff to each element of the array rather than trying to
concatenate a string to an array, which as others have said will absolutely
not work.


Yep.


I can't guarantee that the above code is the best performant method, but it
works. :-)


It certainly does. Of course I'm not using it exactly how you pasted
it, but you got me on track. Thank you very much.

To all others who took part in this thread: I was unclear on another
point as well, the issue of sql-injection. As I'm removing the
symbols, signs, and other non-alpha characters from the query, I
expect it to be sql-injection proof. As I wrong? ie, could an attacker
successful inject sql if he has nothing but alpha characters at his
disposal? I think not, but I'd like to hear it from someone with more
experience than i.

Thank you.

Dotan Cohen

http://what-is-what.com

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



Re: [PHP] str_replace on words with an array

2006-11-03 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-30 21:18:33 +:
 Dotan Cohen wrote:
  $searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);
 
 Ok, this is what the compiler will see...
 
 $searchQuery=str_replace(^Array$,  , $searchQuery);
 
 Yes, that's a literal Array in the string. You cannot, and you should
 remember this, you cannot concatenate strings and arrays. What would you
 expect it to do?

DTRT? This is what e. g. zsh does with the right configuration:

[EMAIL PROTECTED] ~ 1108:0  echo x-{aa,bb,cc}-y
x-aa-y x-bb-y x-cc-y

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] str_replace on words with an array

2006-11-03 Thread Richard Lynch
On Fri, November 3, 2006 5:30 am, Dotan Cohen wrote:
 To all others who took part in this thread: I was unclear on another
 point as well, the issue of sql-injection. As I'm removing the
 symbols, signs, and other non-alpha characters from the query, I
 expect it to be sql-injection proof. As I wrong? ie, could an attacker
 successful inject sql if he has nothing but alpha characters at his
 disposal? I think not, but I'd like to hear it from someone with more
 experience than i.

In Latin1, ISO-8891-1 or whatever, plain old not-quite-ASCII, yeah,
you should be safe, I think...

I'm making *no* promises if your DB is configured to accept some
*other* character set, or the Bad Guy manages to trick it into
thinking it should be using that charset.

Why the big deal about just calling mysql_real_escape_string() on your
data?

Or using prepared statements and that ilk?

Then you'd be 100% sure, and not worrying about it, eh?

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] str_replace on words with an array

2006-10-30 Thread Jochem Maas
Dotan Cohen wrote:
 I need to remove the noise words from a search string. I can't seem to
 get str_replace to go through the array and remove the words, and I'd
 rather avoid a redundant foreach it I can. According to TFM
 str_replace should automatically go through the whole array, no? Does
 anybody see anything wrong with this code:
 
 $noiseArray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
 \, ', :, ;, |, \\, , , ,, ., ?, $, !,
 @, #, $, %, ^, , *, (, ), -, _, +, =, [,
 ], {, }, about, after, all, also, an, and,
 another, any, are, as, at, be, because, been,
 before, being, between, both, but, by, came, can,
 come, could, did, do, does, each, else, for, from,
 get, got, has, had, he, have, her, here, him,
 himself, his, how, if, in, into, is, it, its,
 just, like, make, many, me, might, more, most, much,
 must, my, never, now, of, on, only, or, other,
 our, out, over, re, said, same, see, should, since,
 so, some, still, such, take, than, that, the, their,
 them, then, there, these, they, this, those, through,
 to, too, under, up, use, very, want, was, way, we,
 well, were, what, when, where, which, while, who,
 will, with, would, you, your, a, b, c, d, e, f,
 g, h, i, j, k, l, m, n, o, p, q, r, s, t,
 u, v, w, x, y, z);
 
 $searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);

it's string replacement not regexp replacement, therefore the '^' and '$' are 
bogus.
the first argument to the str_replace() call is the string literal:

'^Array$'

... you can't concatenate strings and arrays like that (and get the result you 
want)!

instead, your function call should look like this:

$searchQuery = str_replace($noiseArray, ' ', $searchQuery);

 
 Thanks in advance.
 
 Dotan Cohen
 
 http://essentialinux.com
 http://what-is-what.com/what_is/sitepoint.html
 

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



Re: [PHP] str_replace on words with an array

2006-10-30 Thread Jochem Maas
Dotan Cohen wrote:
 I need to remove the noise words from a search string. I can't seem to
 get str_replace to go through the array and remove the words, and I'd
 rather avoid a redundant foreach it I can. According to TFM
 str_replace should automatically go through the whole array, no? Does
 anybody see anything wrong with this code:
 
 $noiseArray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
 \, ', :, ;, |, \\, , , ,, ., ?, $, !,
 @, #, $, %, ^, , *, (, ), -, _, +, =, [,
 ], {, }, about, after, all, also, an, and,
 another, any, are, as, at, be, because, been,
 before, being, between, both, but, by, came, can,
 come, could, did, do, does, each, else, for, from,
 get, got, has, had, he, have, her, here, him,
 himself, his, how, if, in, into, is, it, its,
 just, like, make, many, me, might, more, most, much,
 must, my, never, now, of, on, only, or, other,
 our, out, over, re, said, same, see, should, since,
 so, some, still, such, take, than, that, the, their,
 them, then, there, these, they, this, those, through,
 to, too, under, up, use, very, want, was, way, we,
 well, were, what, when, where, which, while, who,
 will, with, would, you, your, a, b, c, d, e, f,
 g, h, i, j, k, l, m, n, o, p, q, r, s, t,
 u, v, w, x, y, z);
 
 $searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);

// another idea based on further reading of the thread:

function pregify($val) {
foreach ((array)$val $k as $v)
$val[$k] = '\b'.preg_quote($v).'\b';

return $val;
}

$searchQuery = preg_replace(pregify($noiseArray),  , $searchQuery);

 
 Thanks in advance.
 
 Dotan Cohen
 
 http://essentialinux.com
 http://what-is-what.com/what_is/sitepoint.html
 

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



Re: [PHP] str_replace on words with an array

2006-10-30 Thread Ed Lazor
It looks like you guys are coming up with some cool solutions, but I  
have a question.  Wasn't the original purpose of this thread to  
prevent sql injection attacks in input from user forms?  If so,  
wouldn't mysql_real_escape_string be an easier solution?




On Oct 30, 2006, at 8:17 AM, Jochem Maas wrote:


Dotan Cohen wrote:
I need to remove the noise words from a search string. I can't  
seem to

get str_replace to go through the array and remove the words, and I'd
rather avoid a redundant foreach it I can. According to TFM
str_replace should automatically go through the whole array, no? Does
anybody see anything wrong with this code:

$noiseArray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
\, ', :, ;, |, \\, , , ,, ., ?, $, !,
@, #, $, %, ^, , *, (, ), -, _, +, =, [,
], {, }, about, after, all, also, an, and,
another, any, are, as, at, be, because, been,
before, being, between, both, but, by, came, can,
come, could, did, do, does, each, else, for, from,
get, got, has, had, he, have, her, here, him,
himself, his, how, if, in, into, is, it, its,
just, like, make, many, me, might, more, most,  
much,

must, my, never, now, of, on, only, or, other,
our, out, over, re, said, same, see, should, since,
so, some, still, such, take, than, that, the,  
their,

them, then, there, these, they, this, those, through,
to, too, under, up, use, very, want, was, way,  
we,

well, were, what, when, where, which, while, who,
will, with, would, you, your, a, b, c, d, e, f,
g, h, i, j, k, l, m, n, o, p, q, r, s, t,
u, v, w, x, y, z);

$searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);


// another idea based on further reading of the thread:

function pregify($val) {
foreach ((array)$val $k as $v)
$val[$k] = '\b'.preg_quote($v).'\b';

return $val;
}

$searchQuery = preg_replace(pregify($noiseArray),  , $searchQuery);



Thanks in advance.

Dotan Cohen

http://essentialinux.com
http://what-is-what.com/what_is/sitepoint.html



--
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 on words with an array

2006-10-30 Thread Stut

Ed Lazor wrote:
It looks like you guys are coming up with some cool solutions, but I 
have a question.  Wasn't the original purpose of this thread to 
prevent sql injection attacks in input from user forms?  If so, 
wouldn't mysql_real_escape_string be an easier solution?


Me thinkie nottie. From the OP...

I need to remove the noise words from a search string.

However, until the OPer accepts that people are right when they say you 
can't append strings to an array it's never going to work. Every bit of 
sample code posted retains the following line of code rather than fixing 
it according to several other previous posts...


^.$noiseArray.$

Happy happy joy joy, oh look, the spring's broken. Doing!!

-Stut (slightly drunk, but feeling generally good about the world)

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



Re: [PHP] str_replace on words with an array

2006-10-30 Thread Dotan Cohen

On 30/10/06, Stut [EMAIL PROTECTED] wrote:

Ed Lazor wrote:
 It looks like you guys are coming up with some cool solutions, but I
 have a question.  Wasn't the original purpose of this thread to
 prevent sql injection attacks in input from user forms?  If so,
 wouldn't mysql_real_escape_string be an easier solution?

Me thinkie nottie. From the OP...

I need to remove the noise words from a search string.


Yes, that is also part of the aim.


However, until the OPer accepts that people are right when they say you
can't append strings to an array it's never going to work. Every bit of
sample code posted retains the following line of code rather than fixing
it according to several other previous posts...

^.$noiseArray.$


Er, so how would it be done? I've been trying for two days now with no success.


Happy happy joy joy, oh look, the spring's broken. Doing!!


Boing!!!


-Stut (slightly drunk, but feeling generally good about the world)


Dotan Cohen

http://lyricslist.com/
http://what-is-what.com/

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



Re: [PHP] str_replace on words with an array

2006-10-30 Thread Stut
Dotan Cohen wrote:
 Er, so how would it be done? I've been trying for two days now with no
 success.

Ok, I guess my original reply didn't get through, or you ignored it.
Here it is again for your convenience.

Dotan Cohen wrote:
  $searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);

Ok, this is what the compiler will see...

$searchQuery=str_replace(^Array$,  , $searchQuery);

Yes, that's a literal Array in the string. You cannot, and you should
remember this, you cannot concatenate strings and arrays. What would you
expect it to do?

Now, the answer is this...

$searchQuery = str_replace($noiseArray, ' ', $searchQuery);

However, what you seem to be doing is putting regex syntax where it
would have no effect even if $noiseArray was not an array. If your
intention is to replace the words rather than just the strings then you
need to look at preg_replace (http://php.net/preg_replace) and you'll
need to decorate the strings in $noiseArray with the appropriate
characters to make them the search pattern you need - full details on
the preg_replace manual page.

-Stut (painfully sober now :( )

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



Re: [PHP] str_replace on words with an array

2006-10-30 Thread Ed Lazor


On Oct 30, 2006, at 9:19 AM, Stut wrote:


Ed Lazor wrote:
It looks like you guys are coming up with some cool solutions, but  
I have a question.  Wasn't the original purpose of this thread to  
prevent sql injection attacks in input from user forms?  If so,  
wouldn't mysql_real_escape_string be an easier solution?


Me thinkie nottie. From the OP...

I need to remove the noise words from a search string.


You sure?  This is what they said originally:

Nothing else is relevant, but $searchQuery will get passed to the  
database, so it should be protected from SQL injection. That's why I  
want to remove characters such as quotes, dashes, and the equals sign.


Maybe that doesn't account for all of the extra words they're trying  
to remove... dunno, thus my question.



However, until the OPer accepts that people are right when they say  
you can't append strings to an array it's never going to work.  
Every bit of sample code posted retains the following line of code  
rather than fixing it according to several other previous posts...


^.$noiseArray.$

Happy happy joy joy, oh look, the spring's broken. Doing!!


Persistence is a virtue? hehe



-Stut (slightly drunk, but feeling generally good about the world)


Hy.  That's not fair.  No bragging unless you plan on  
sharing :)


-Ed

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



Re: [PHP] str_replace on words with an array

2006-10-30 Thread Larry Garfield
On Monday 30 October 2006 15:10, Dotan Cohen wrote:

 Er, so how would it be done? I've been trying for two days now with no
 success.

From your original message, it sounds like you want to strip selected complete 
words, not substrings, from a string for indexing or searching or such.  
Right?

Try something like this:

$string = The quick sly fox jumped over a fence and ran away;
$words = array('the', 'a', 'and');

function make_regex($str) {
  return '/\b' . $str . '\b/i';
}

$search = array_map('make_regex', $words);
$string = preg_replace($search, '', $string);
print $string . \n;

What you really need to do that is to match word boundaries, NOT string 
boundaries.  So you take your list of words and mutate *each one* (that's 
what the array_map() is about) into a regex pattern that finds that word, 
case-insensitively.  Then you use preg_replace() to replace all matches of 
any of those patterns with an empty string.  

You were close.  What you were missing was the array_map(), because you needed 
to concatenate stuff to each element of the array rather than trying to 
concatenate a string to an array, which as others have said will absolutely 
not work.

I can't guarantee that the above code is the best performant method, but it 
works. :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



Re: [PHP] str_replace on words with an array

2006-10-30 Thread Ed Lazor


On Oct 30, 2006, at 1:10 PM, Dotan Cohen wrote:


On 30/10/06, Stut [EMAIL PROTECTED] wrote:

Ed Lazor wrote:
 It looks like you guys are coming up with some cool solutions,  
but I

 have a question.  Wasn't the original purpose of this thread to
 prevent sql injection attacks in input from user forms?  If so,
 wouldn't mysql_real_escape_string be an easier solution?

Me thinkie nottie. From the OP...

I need to remove the noise words from a search string.


Yes, that is also part of the aim.


How come?  Not trying to be facetious here.  I'm just wondering if  
you see a benefit that I don't.  For example, say the hacker injects  
some sql and you use mysql_real_escape_string.  You end up with  
something like this... actually, I'll do one step further and just  
use the quote_smart function described in the  
mysql_real_escape_string page of the php manual:


$query = sprintf(SELECT * FROM users WHERE user=%s AND password=%s,
quote_smart($_POST['username']),
quote_smart($_POST['password']) );

Say the user tried to inject sql in $_POST['username'] and it looked  
something like:   root';drop all;


Having used quote_smart, the value of $query ends up

SELECT * FROM users WHERE user='root\'\;drop all\;' AND  
password='something'


The sql injection fails.  The data is seen as a literal.  The  
database is going to think there's no user with that name.  That  
means that even if the user did include extra words, they're just  
part of the value that is checked against user names - rather than  
being see as potential commands.


I'm not sure if I'm describing this well, so let me know what you  
think and I'll go from there.


-Ed

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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Børge Holen
Yes you need to put some \ in front of some of those characters

On Sunday 29 October 2006 21:05, Dotan Cohen wrote:
 I need to remove the noise words from a search string. I can't seem to
 get str_replace to go through the array and remove the words, and I'd
 rather avoid a redundant foreach it I can. According to TFM
 str_replace should automatically go through the whole array, no? Does
 anybody see anything wrong with this code:

 $noiseArray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
 \, ', :, ;, |, \\, , , ,, ., ?, $, !,
 @, #, $, %, ^, , *, (, ), -, _, +, =, [,
 ], {, }, about, after, all, also, an, and,
 another, any, are, as, at, be, because, been,
 before, being, between, both, but, by, came, can,
 come, could, did, do, does, each, else, for, from,
 get, got, has, had, he, have, her, here, him,
 himself, his, how, if, in, into, is, it, its,
 just, like, make, many, me, might, more, most, much,
 must, my, never, now, of, on, only, or, other,
 our, out, over, re, said, same, see, should, since,
 so, some, still, such, take, than, that, the, their,
 them, then, there, these, they, this, those, through,
 to, too, under, up, use, very, want, was, way, we,
 well, were, what, when, where, which, while, who,
 will, with, would, you, your, a, b, c, d, e, f,
 g, h, i, j, k, l, m, n, o, p, q, r, s, t,
 u, v, w, x, y, z);

 $searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);

 Thanks in advance.

 Dotan Cohen

 http://essentialinux.com
 http://what-is-what.com/what_is/sitepoint.html

-- 
---
Børge
Kennel Arivene 
http://www.arivene.net
---

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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Dotan Cohen

On 29/10/06, Alan Milnes [EMAIL PROTECTED] wrote:

Dotan Cohen wrote:
 $searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);
Can you explain what you are trying to do with the ^ and $?  What is a
typical value of the original $searchQuery?

Alan



The purpose of the ^ and the $ is to define the beginning and the end of a word:
http://il2.php.net/regex

I also tried str_replace( $noiseArray,  , $searchQuery) but that was
replacing the insides of words as well. And with the addition of the
individual letters, that emptied the entire $searchQuery string!

A typical value of $searchQuery could be What is php? or What is
open source. See this site for details:
http://what-is-what.com

Dotan Cohen

http://technology-sleuth.com/

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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Paul Novitski

At 10/29/2006 01:07 PM, Dotan Cohen wrote:
The purpose of the ^ and the $ is to define the beginning and the 
end of a word:

http://il2.php.net/regex



No, actually, ^ and $ define the beginnning  end of the entire 
expression being searched, not the boundaries of a single 
word.  Therefore searching for ^mouse$ will locate mouse only if 
it's the only word in the entire string, which I gather is not what you want.


I suspect what you want is either this:

(^| )WORD( |$)

(the word bounded by either the start/end of string or a space)

or perhaps better yet this:

\bWORD\b

(the word bounded by word boundaries).

See [PCRE regex] Pattern Syntax
http://il2.php.net/manual/en/reference.pcre.pattern.syntax.php



Further to your problem, I believe this is incorrect:

$noiseArray = array(1, ...
...
$searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);

Since $noiseArray is your entire array, it doesn't make sense to 
enclose it in word boundaries of any kind.  Instead, I imagine each 
member of the array needs to be bounded individually.


If you go this route, perhaps you could enclose each member of your 
original array in \b word boundary sequences using an array_walk 
routine so that you don't have to muddy your original array 
declaration statement.


Regards,
Paul 


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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Myron Turner

I never use this function, since I always use regular expressions, but
according to the manual:
 If you don't need fancy replacing rules (like regular
 expressions), you should always use this function instead of
 ereg_replace() or preg_replace().

So, I assume your problem initially was that you were using regular
expression syntax and this function doesn't accept regular expressions.

Is your aim to get rid strings of all the items in the $noiseArray? Your
 $noiseArray includes the entire alpahabet, so it's no wonder that you
end up with empty strings!

Myron

Dotan Cohen wrote:

On 29/10/06, Alan Milnes [EMAIL PROTECTED] wrote:

Dotan Cohen wrote:
 $searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);
Can you explain what you are trying to do with the ^ and $?  What is a
typical value of the original $searchQuery?

Alan



The purpose of the ^ and the $ is to define the beginning and the end of 
a word:

http://il2.php.net/regex

I also tried str_replace( $noiseArray,  , $searchQuery) but that was
replacing the insides of words as well. And with the addition of the
individual letters, that emptied the entire $searchQuery string!

A typical value of $searchQuery could be What is php? or What is
open source. See this site for details:
http://what-is-what.com

Dotan Cohen

http://technology-sleuth.com/



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread rich gray

Paul Novitski wrote:


If you go this route, perhaps you could enclose each member of your 
original array in \b word boundary sequences using an array_walk 
routine so that you don't have to muddy your original array 
declaration statement.


IIRC str_replace() does not interpret or understand regular expression 
syntax - you'd need preg_replace() for that

rich


Re: [PHP] str_replace on words with an array

2006-10-29 Thread Stut
Dotan Cohen wrote:
 $searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);

Ok, this is what the compiler will see...

$searchQuery=str_replace(^Array$,  , $searchQuery);

Yes, that's a literal Array in the string. You cannot, and you should
remember this, you cannot concatenate strings and arrays. What would you
expect it to do?

Now, the answer is this...

$searchQuery = str_replace($noiseArray, ' ', $searchQuery);

However, what you seem to be doing is putting regex syntax where it
would have no effect even if $noiseArray was not an array. If your
intention is to replace the words rather than just the strings then you
need to look at preg_replace (http://php.net/preg_replace) and you'll
need to decorate the strings in $noiseArray with the appropriate
characters to make them the search pattern you need - full details on
the preg_replace manual page.

Hope that made sense.

-Stut

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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Dotan Cohen

On 29/10/06, Børge Holen [EMAIL PROTECTED] wrote:

Yes you need to put some \ in front of some of those characters

On Sunday 29 October 2006 21:05, Dotan Cohen wrote:
 I need to remove the noise words from a search string. I can't seem to
 get str_replace to go through the array and remove the words, and I'd
 rather avoid a redundant foreach it I can. According to TFM
 str_replace should automatically go through the whole array, no? Does
 anybody see anything wrong with this code:

 $noiseArray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
 \, ', :, ;, |, \\, , , ,, ., ?, $, !,
 @, #, $, %, ^, , *, (, ), -, _, +, =, [,
 ], {, }, about, after, all, also, an, and,
 another, any, are, as, at, be, because, been,
 before, being, between, both, but, by, came, can,
 come, could, did, do, does, each, else, for, from,
 get, got, has, had, he, have, her, here, him,
 himself, his, how, if, in, into, is, it, its,
 just, like, make, many, me, might, more, most, much,
 must, my, never, now, of, on, only, or, other,
 our, out, over, re, said, same, see, should, since,
 so, some, still, such, take, than, that, the, their,
 them, then, there, these, they, this, those, through,
 to, too, under, up, use, very, want, was, way, we,
 well, were, what, when, where, which, while, who,
 will, with, would, you, your, a, b, c, d, e, f,
 g, h, i, j, k, l, m, n, o, p, q, r, s, t,
 u, v, w, x, y, z);

 $searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);

 Thanks in advance.



I improved the $noiseArray to this:

$noiseArray = array([:alnum:], [:punct:], |, \\, , ,
#, @,  \$, %, ^, , *, (, ), -, _, +, =,
[, ], {, }, about, after, all, also, an, and,
another, any, are, as, at, be, because, been,
before, being, between, both, but, by, came, can,
come, could, did, do, does, each, else, for, from,
get, got, has, had, he, have, her, here, him,
himself, his, how, if, in, into, is, it, its,
just, like, make, many, me, might, more, most, much,
must, my, never, now, of, on, only, or, other,
our, out, over, re, said, same, see, should, since,
so, some, still, such, take, than, that, the, their,
them, then, there, these, they, this, those, through,
to, too, under, up, use, very, want, was, way, we,
well, were, what, when, where, which, while, who,
will, with, would, you, your);

Do any of the characters in there need escaping (other than the $
which is already escaped)?

How does on go about looping through the array, matching only whole
words? This didn't quite do it:
$searchQuery=str_replace( ^.$noiseArray.$,  , $searchQuery);

And neither did this:
$searchQuery=str_replace( /^.$noiseArray.$/,  , $searchQuery);

Thanks.

Dotan Cohen
http://dotancohen.com
http://what-is-what.com/what_is/drm.html


Re: [PHP] str_replace on words with an array

2006-10-29 Thread Paul Novitski



Paul Novitski wrote:
If you go this route, perhaps you could enclose each member of your 
original array in \b word boundary sequences using an array_walk 
routine so that you don't have to muddy your original array 
declaration statement.


At 10/29/2006 01:54 PM, rich gray wrote:
IIRC str_replace() does not interpret or understand regular 
expression syntax - you'd need preg_replace() for that



You're absolutely right -- I was focusing so much on the regexp 
syntax that I failed to broaden my gaze...


When the OP corrects his PHP to use preg_replace() instead of 
str_replace(), I believe he'll still need to provide word boundaries 
around each member of his noise-word array, otherwise the function 
will simply remove all letters and digits from the words in the 
search-string he considers meaningful and he'll end up searching thin air.


Aside, without knowing the context of his search, it seems a bit 
extreme to remove all single characters from the search string.  It's 
not hard to think of examples of them occurring as part of valid 
entity names in our universe -- she got an A, Plan B From Outer 
Space, Vitamin C, etc.


An alternative strategy might be to trust the user to enter a valid 
search string and simply warn them that the quality of the answer 
they get will depend on the quality of their input.


Regards,
Paul 


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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Dotan Cohen

Thanks all for the heads up with the str_replace not working with
regexes. Duh! I've switched to preg_replace, but still no luck. (nor
skill, on my part)

I'm trying to use array_walk to go through the array and deliminate
each item with /b so that the preg_replace function will know to only
operate on whole words, but I just can't seem to get it. I am of
course Ring TFM and Sing THW but with no luck. A push (link to TFA or
tutorial, whatever) would be most appreciated.

Thanks again.

Dotan Cohen
http://what-is-what.com/what_is/love.html

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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Stut
Dotan Cohen wrote:
 Thanks all for the heads up with the str_replace not working with
 regexes. Duh! I've switched to preg_replace, but still no luck. (nor
 skill, on my part)
 
 I'm trying to use array_walk to go through the array and deliminate
 each item with /b so that the preg_replace function will know to only
 operate on whole words, but I just can't seem to get it. I am of
 course Ring TFM and Sing THW but with no luck. A push (link to TFA or
 tutorial, whatever) would be most appreciated.

IMHO, unless you're going to be doing a lot with each element of the
array it's easier to do it without using array_walk.

foreach ($arr as $key = $val)
$arr[$key] = \\b.$val.\\b;

-Stut

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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Dotan Cohen

On 30/10/06, Paul Novitski [EMAIL PROTECTED] wrote:

Hi Dotan,

To get help with your problem, share more of your PHP code with the
list so we can look at what you're doing.

Also, give us a link to the PHP script on your server so we can see the output.

Regards,
Paul



Nothing else is relevant, but $searchQuery will get passed to the
database, so it should be protected from SQL injection. That's why I
want to remove characters such as quotes, dashes, and the equals sign.

I set up a test page:
http://what-is-what.com/test.php

with this code:
htmlbody

?php

// FOIL SQL INJECTION AND REMOVE NOISE

$noiseArray = array([:alnum:], [:punct:], |, \\, , ,
#, @,  \$, %, ^, , *, (, ), -, _, +, =,
[, ], {, }, about, after, all, also, an, and,
another, any, are, as, at, be, because, been,
before, being, between, both, but, by, came, can,
come, could, did, do, does, each, else, for, from,
get, got, has, had, he, have, her, here, him,
himself, his, how, if, in, into, is, it, its,
just, like, make, many, me, might, more, most, much,
must, my, never, now, of, on, only, or, other,
our, out, over, re, said, same, see, should, since,
so, some, still, such, take, than, that, the, their,
them, then, there, these, they, this, those, through,
to, too, under, up, use, very, want, was, way, we,
well, were, what, when, where, which, while, who,
will, with, would, you, your);

$searchQuery=preg_replace( /^.$noiseArray.$/,  , $_POST[query]);
$searchQuery=trim($searchQuery);

print p$searchQuery/p;

?

form action=/test.php method=post
  input type=text name=query /
  input type=submit /
/form

/body/html



Dotan Cohen

http://song-lirics.com
http://what-is-what.com/what_is/distribution.html

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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Ed Lazor

checkout the function mysql_real_escape_string()


On Oct 29, 2006, at 3:13 PM, Dotan Cohen wrote:


On 30/10/06, Paul Novitski [EMAIL PROTECTED] wrote:

Hi Dotan,

To get help with your problem, share more of your PHP code with the
list so we can look at what you're doing.

Also, give us a link to the PHP script on your server so we can  
see the output.


Regards,
Paul



Nothing else is relevant, but $searchQuery will get passed to the
database, so it should be protected from SQL injection. That's why I
want to remove characters such as quotes, dashes, and the equals sign.

I set up a test page:
http://what-is-what.com/test.php

with this code:
htmlbody

?php

// FOIL SQL INJECTION AND REMOVE NOISE

$noiseArray = array([:alnum:], [:punct:], |, \\, , ,
#, @,  \$, %, ^, , *, (, ), -, _, +, =,
[, ], {, }, about, after, all, also, an, and,
another, any, are, as, at, be, because, been,
before, being, between, both, but, by, came, can,
come, could, did, do, does, each, else, for, from,
get, got, has, had, he, have, her, here, him,
himself, his, how, if, in, into, is, it, its,
just, like, make, many, me, might, more, most, much,
must, my, never, now, of, on, only, or, other,
our, out, over, re, said, same, see, should, since,
so, some, still, such, take, than, that, the, their,
them, then, there, these, they, this, those, through,
to, too, under, up, use, very, want, was, way, we,
well, were, what, when, where, which, while, who,
will, with, would, you, your);

$searchQuery=preg_replace( /^.$noiseArray.$/,  , $_POST 
[query]);

$searchQuery=trim($searchQuery);

print p$searchQuery/p;

?

form action=/test.php method=post
  input type=text name=query /
  input type=submit /
/form

/body/html



Dotan Cohen

http://song-lirics.com
http://what-is-what.com/what_is/distribution.html

--
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(), and correctly positioned HTML tags

2006-05-26 Thread Jochem Maas

Dave M G wrote:

PHP list,



...

take a look at: http://textism.com/ especially the 'textism' stuff which if
nothing else mgiht give you some good ideas about plain text markup for
conversion to HTML.



--
Dave M G



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



Re: [PHP] str_replace(), and correctly positioned HTML tags

2006-05-26 Thread tedd

At 12:26 PM +0900 5/26/06, Dave M G wrote:

Tedd, Adam,

Thank you for your advice. While I'm very grateful for your advice, 
unfortunately, it seems that the core of what you suggest do not fit 
my situation.


First, with Adam's suggestion that I use br / instead of p. The 
output I am generating is akin to what csszengarden.com generates, 
so that I can have complete CSS control over page layout and style. 
br / tags are limited in their scope of design control as compared 
to p tags, so they are insufficient.


Second, with Tedd's advice that I place the variable without 
formatting within the HTML code. I apologize if I was unclear, as I 
seem to have given you the wrong impression. I am absolutely trying 
to separate content from design, which is why everything the user 
stores is in plain text, and all the formatting happens when it is 
displayed. None of the modifications which add HTML to the variable 
get put back into the database.


The only small formatting consideration that does get stored in the 
database are the simulated tags (eg: --++ for h3). I'm not totally 
thrilled about letting users create some formatting with simulated 
tags, but the trade off is for giving the users more flexibility. 
I'm following the same model as WikiMedia, SMF Forums, and other PHP 
based user input interfaces. And I am trying to be more strict and 
less expansive than they are.


I really am grateful for your advice, but it seems that I really do 
need to find a way to create p tags around the text when it is 
displayed.


But I definitely thank you for giving me something to think about, 
and also the tips on how to make my code more efficient.


It's my hope that someone can still steer me towards the ability to 
get p tags surrounding paragraphs, and to be able to separate h3 
and other tags from within those p tags.


--
Dave M G



Dave:

If you want to go that way, then I suggest that you place a preview 
page for the poster. Most people don't want to post something that's 
all screwed up and will take the time to fix it IF they are given the 
chance.


That way, the only real problem you have to deal with is what happens 
when someone enters something that isn't correct.


I might also suggest that there are functions that will help you sort 
out acceptable html from unacceptable html.


For example, strip_tags($text, 'p'); will allow both p and /p 
tags, but will prohibit everything else.


If you want a more complete answer to your problem, you can use 
regular expressions to extract and manipulate tags, but it's complex.


A good read, and what appears to be a solution, can be found on pages 
153-159 of PHP String Handling Handbook by Matt Wade et al published 
by Wrok (ISBN 1-86100-835-X) in 2003.


I've looked for the download support files they claim to have, but found none.

http://support.apress.com/books.asp?bID=186100835xs=0Go=Select+Book

I've contacted one of the authors, let's see if he provides the code. 
If he does, I'll send it to you.


hth's.

tedd

--

http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] str_replace(), and correctly positioned HTML tags

2006-05-26 Thread Jochem Maas

with regard to clean HTML - check out the tidy extension - it can do wonders
with crufty output.

http://php.net/tidy

tedd wrote:

At 12:26 PM +0900 5/26/06, Dave M G wrote:


Tedd, Adam,

Thank you for your advice. While I'm very grateful for your advice, 
unfortunately, it seems that the core of what you suggest do not fit 
my situation.


First, with Adam's suggestion that I use br / instead of p. The 
output I am generating is akin to what csszengarden.com generates, so 
that I can have complete CSS control over page layout and style. br 
/ tags are limited in their scope of design control as compared to 
p tags, so they are insufficient.


Second, with Tedd's advice that I place the variable without 
formatting within the HTML code. I apologize if I was unclear, as I 
seem to have given you the wrong impression. I am absolutely trying to 
separate content from design, which is why everything the user stores 
is in plain text, and all the formatting happens when it is displayed. 
None of the modifications which add HTML to the variable get put back 
into the database.


The only small formatting consideration that does get stored in the 
database are the simulated tags (eg: --++ for h3). I'm not totally 
thrilled about letting users create some formatting with simulated 
tags, but the trade off is for giving the users more flexibility. I'm 
following the same model as WikiMedia, SMF Forums, and other PHP based 
user input interfaces. And I am trying to be more strict and less 
expansive than they are.


I really am grateful for your advice, but it seems that I really do 
need to find a way to create p tags around the text when it is 
displayed.


But I definitely thank you for giving me something to think about, and 
also the tips on how to make my code more efficient.


It's my hope that someone can still steer me towards the ability to 
get p tags surrounding paragraphs, and to be able to separate h3 
and other tags from within those p tags.


--
Dave M G




Dave:

If you want to go that way, then I suggest that you place a preview 
page for the poster. Most people don't want to post something that's all 
screwed up and will take the time to fix it IF they are given the chance.


That way, the only real problem you have to deal with is what happens 
when someone enters something that isn't correct.


I might also suggest that there are functions that will help you sort 
out acceptable html from unacceptable html.


For example, strip_tags($text, 'p'); will allow both p and /p 
tags, but will prohibit everything else.


If you want a more complete answer to your problem, you can use regular 
expressions to extract and manipulate tags, but it's complex.


A good read, and what appears to be a solution, can be found on pages 
153-159 of PHP String Handling Handbook by Matt Wade et al published by 
Wrok (ISBN 1-86100-835-X) in 2003.


I've looked for the download support files they claim to have, but found 
none.


http://support.apress.com/books.asp?bID=186100835xs=0Go=Select+Book

I've contacted one of the authors, let's see if he provides the code. If 
he does, I'll send it to you.


hth's.

tedd



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



Re: [PHP] str_replace(), and correctly positioned HTML tags

2006-05-25 Thread tedd

At 12:53 AM +0900 5/26/06, Dave M G wrote:

PHP list,

This may be a simple matter. Please feel free to tell me to RTFM if 
you can direct me to exactly where in the FM to R. Or, alternately, 
please use simple explanations, as I'm not an experienced PHP coder.


I'm building a simple content management system, where users can 
enter text into a web form. The text is stored in a MySQL database. 
The text should be plain text.


When the text is retrieved from the database for display, I want to 
add some HTML tags so I can control the format with an external CSS.


I'm assuming the best way to do this is with str_replace(). But 
there are some complications which make me unsure of its usage.


Dave:

RTFM -- yeah, unfortunately, there's a lot of that going around -- 
most justified, some not.


In any event, I think this is where you're going wrong -- don't use 
str_replace() to alter the *content* at all !


If you know css, then keep the content separate from presentation. 
Content comes from your mysql and you should be able to place it 
within html markup where its presentation is controlled by css.


For example, if I have a text paragraph ($my_paragraph) that's been 
pulled from mysql and I want to show that paragraph in html, then I 
would do something like this:


div=content
p
?php echo($my_paragraph); ?
/p
/div

That way I use use css to control how that paragraph will look with 
those div and p tags and, at the same time, make the content easy 
to handle.


If you want to allow users to enter html tags themselves, then you're 
asking for a bit of trouble IMO because you are relying upon them to 
do the mark-up correctly.


For example, if someone entered h1This is what I want to say/h1 
-- how would you handle it? Also note that if that was entered 
as-is your page would not longer be well formed and would probably 
cause problems with the rest of your page, not to mention not 
validating.


If you think you can write code to fix their mistakes, then I think 
that's a mistake for users can screw up code even more than 
programmers can. :-)


Additionally, if you don't handle the input right, then there's a 
security concern, such as mysql injection.


If you want to give your users the option of having headlines and 
body of work, then provide a Headline box and Body of Work box and 
then manage those entries in your markup.


I think you get the idea.

I'm sure there are other ways to do this, but this is the way I've done it.

hth's

tedd

--

http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] str_replace(), and correctly positioned HTML tags

2006-05-25 Thread Dave M G

Tedd, Adam,

Thank you for your advice. While I'm very grateful for your advice, 
unfortunately, it seems that the core of what you suggest do not fit my 
situation.


First, with Adam's suggestion that I use br / instead of p. The 
output I am generating is akin to what csszengarden.com generates, so 
that I can have complete CSS control over page layout and style. br / 
tags are limited in their scope of design control as compared to p 
tags, so they are insufficient.


Second, with Tedd's advice that I place the variable without formatting 
within the HTML code. I apologize if I was unclear, as I seem to have 
given you the wrong impression. I am absolutely trying to separate 
content from design, which is why everything the user stores is in plain 
text, and all the formatting happens when it is displayed. None of the 
modifications which add HTML to the variable get put back into the database.


The only small formatting consideration that does get stored in the 
database are the simulated tags (eg: --++ for h3). I'm not totally 
thrilled about letting users create some formatting with simulated tags, 
but the trade off is for giving the users more flexibility. I'm 
following the same model as WikiMedia, SMF Forums, and other PHP based 
user input interfaces. And I am trying to be more strict and less 
expansive than they are.


I really am grateful for your advice, but it seems that I really do need 
to find a way to create p tags around the text when it is displayed.


But I definitely thank you for giving me something to think about, and 
also the tips on how to make my code more efficient.


It's my hope that someone can still steer me towards the ability to get 
p tags surrounding paragraphs, and to be able to separate h3 and 
other tags from within those p tags.


--
Dave M G

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



Re: [PHP] str_replace ? \r

2006-02-07 Thread Jay Paulson
http://us3.php.net/manual/en/function.nl2br.php

Instead of using br / I would use p/p tags.  That's just me though. :)


On 2/7/06 12:38 PM, Sam Smith [EMAIL PROTECTED] wrote:

 
 From a textarea on a web form I'm attempting to convert all returns(\r),
 from the users input, to br /, for db INSERT, and then back again for
 display in the textarea. (They remain as br /s for normal HTML web page
 display.)
 
 code:
 // From textarea to db UPDATE
 function addBR($tv) {
 $tv = addslashes($tv);
 $tv = str_replace(\r,br /,$tv);
 //  $tv = preg_replace(/(\r\n|\n|\r)/, br /, $tv);
 //  $tv = preg_replace(/(\r\n|\n|\r)/, , $tv);
 return $tv;}
 
 // For display in textarea
 function remBR($tv) {
 $tv = str_replace(br /,\r,$tv);
 $tv = stripslashes($tv);
 return $tv;
 }
 
 IT ALL works fine accept if a return is entered in the form's textarea at
 the very beginning:
 
 mysql SELECT jbs_jobDesA FROM jobs WHERE jbs_ID=77 \G
 *** 1. row ***
 jbs_jobDesA: br /[the return is still here]
 Lesequam coreet la feum nulla feu facil iriure faccummolut ulput num augait
 1 row in set (0.00 sec)
 
 the return is converted to br /\r (leaving the return). AND then when
 converted back for for the textarea both are stripped out, that is, there
 is nothing in front of the first character. When resubmitted for UPDATE:
 
  mysql SELECT jbs_jobDesA FROM jobs WHERE jbs_ID=77 \G
 *** 1. row ***
 jbs_jobDesA: Lesequam coreet la feum nulla feu facil iriure faccummolut
 ulput num augait 
 1 row in set (0.00 sec)
 
 Q. Why is that first return treated differently? All other returns are
 treated as expected.
 
 Thanks,
 sam

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



Re: [PHP] str_replace ? \r

2006-02-07 Thread Curt Zirzow
On Tue, Feb 07, 2006 at 10:38:37AM -0800, Sam Smith wrote:
 
 From a textarea on a web form I'm attempting to convert all returns(\r),
 from the users input, to br /, for db INSERT, and then back again for
 display in the textarea. (They remain as br /s for normal HTML web page
 display.)

You really shouldnt convert the data to br's into the database,
just do it at the time at displaying it in html, and keep the raw
data in the database.

// add to database (prepare avoiding sql injection)
$field = mysql_real_escape_string($_POST['textarea']);
$sql = update jobs  set jbs_jobDesA = '$field'  WHERE jbs_ID=77;

// output to html, removing xxs ablity and add html br's
$field_from_db = $row['jbs_jobDesA'];
echo div . nl2br(htmlentities($field_from_db)) . /div;

// output to a textarea, removing xxs ability
$field_from_db = $row['jbs_jobDesA'];
echo textarea . htmlentities($field_from_db) . /textarea;

This would work much nicer. No need to do any two-way convertion of
your data.

Curt.
-- 
cat .signature: No such file or directory

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



Re: [PHP] str_replace ? \r

2006-02-07 Thread Matty Sarro
Agreed - try to think of it as a filter and less of something that needs to
be computed both ways... much easier in the long run, and more efficient :)

On 2/7/06, Curt Zirzow [EMAIL PROTECTED] wrote:

 On Tue, Feb 07, 2006 at 10:38:37AM -0800, Sam Smith wrote:
 
  From a textarea on a web form I'm attempting to convert all
 returns(\r),
  from the users input, to br /, for db INSERT, and then back again
 for
  display in the textarea. (They remain as br /s for normal HTML web
 page
  display.)

 You really shouldnt convert the data to br's into the database,
 just do it at the time at displaying it in html, and keep the raw
 data in the database.

 // add to database (prepare avoiding sql injection)
 $field = mysql_real_escape_string($_POST['textarea']);
 $sql = update jobs  set jbs_jobDesA = '$field'  WHERE jbs_ID=77;

 // output to html, removing xxs ablity and add html br's
 $field_from_db = $row['jbs_jobDesA'];
 echo div . nl2br(htmlentities($field_from_db)) . /div;

 // output to a textarea, removing xxs ability
 $field_from_db = $row['jbs_jobDesA'];
 echo textarea . htmlentities($field_from_db) . /textarea;

 This would work much nicer. No need to do any two-way convertion of
 your data.

 Curt.
 --
 cat .signature: No such file or directory

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




Re: [PHP] str_replace ? \r

2006-02-07 Thread Curt Zirzow
On Tue, Feb 07, 2006 at 03:43:38PM -0800, Curt Zirzow wrote:
 On Tue, Feb 07, 2006 at 10:38:37AM -0800, Sam Smith wrote:
 
 // output to html, removing xxs ablity and add html br's

I mean XSS (Cross Site Scripting)

Curt.
-- 
cat .signature: No such file or directory

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



Re: [PHP] str_replace

2005-10-10 Thread Rory Browne
I'm not completely sure, but I think they're talking shite. If curl is
a security problem, then disable curl. They seem from what you've
said, to be pretty irrational. I respect security paranoia, but this
is ridicules.

You could try replacing every letter in the word curl with it's #xxx;
equivlent, but that might not work. You would also have to do it in
JS, although I think that any browser with the exception on lynx has
JS capabilities.

On 10/10/05, Charles Stuart [EMAIL PROTECTED] wrote:
 Hi,

 I'm on shared hosting. Because of security concerns on their part
 [1], every time the text curl u is inputted, a 403 forbidden is
 given and the form is not submitted. This is of course a problem as
 I'm doing work for a children's literacy program, and plenty of
 people try to input curl up with a book.

 I'm trying to use 'str_replace' to solve this issue, but I can't seem
 to get around the 403 error.

 It appears as if the hosting service doesn't give me a chance to
 replace curl u with something else prior to them blocking the
 attempted submit.

 I can tell my str_replace is working as if I change the searched text
 to something other than curl u it does in fact replace it and
 submit it correctly.

 Anyone have any ideas for a workaround? My next thought is to use
 javascript, but I think the site serves quite a few people who might
 not have javascript on.

 Thanks for listening. Below is the PHP [2].


 best,

 Charles


 [2]
 // Grabbing the data from the form.

 if ($task == updateInfo)
  {
 $activityChallenges = cs_remove_curl_up(sanitize_paranoid_string
 ($_POST[activityChallenges]));
  }



 // change curl u to EDIT kurl u

 function cs_remove_curl_up($string, $min='', $max='')
 {
$string = str_replace(curl u, EDIT kurl u, $string);
$len = strlen($string);
if((($min != '')  ($len  $min)) || (($max != '')  ($len 
 $max)))
  return FALSE;
return $string;
 }



 [1]
 My host told me this:

 Mod_security is restricting this and blocks all url's with C-url.
 This is done because of some php worms that are spread using c-url. I
 would recommend trying to work around this. It will be a major
 security issue for us to allow this.

 --
 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

2005-10-10 Thread Charles Stuart
A student run server on my old campus used to turn off PHP for  
security reasons - ridiculous.


Would it be possible to use XSS to call curl from a remote site? I'm  
just a beginner so that may or not make sense.


Indeed it does seem like JS is the solution - unfortunately - as it  
seems like their 'trap' catches any string including CURL U before I  
can str_replace the string after gathering the input with _POST.  
Anyone disagree?




best,

Charles



On Oct 10, 2005, at 3:12 PM, Rory Browne wrote:


I'm not completely sure, but I think they're talking shite. If curl is
a security problem, then disable curl. They seem from what you've
said, to be pretty irrational. I respect security paranoia, but this
is ridicules.

You could try replacing every letter in the word curl with it's #xxx;
equivlent, but that might not work. You would also have to do it in
JS, although I think that any browser with the exception on lynx has
JS capabilities.

On 10/10/05, Charles Stuart [EMAIL PROTECTED] wrote:


Hi,

I'm on shared hosting. Because of security concerns on their part
[1], every time the text curl u is inputted, a 403 forbidden is
given and the form is not submitted. This is of course a problem as
I'm doing work for a children's literacy program, and plenty of
people try to input curl up with a book.

I'm trying to use 'str_replace' to solve this issue, but I can't seem
to get around the 403 error.

It appears as if the hosting service doesn't give me a chance to
replace curl u with something else prior to them blocking the
attempted submit.

I can tell my str_replace is working as if I change the searched text
to something other than curl u it does in fact replace it and
submit it correctly.

Anyone have any ideas for a workaround? My next thought is to use
javascript, but I think the site serves quite a few people who might
not have javascript on.

Thanks for listening. Below is the PHP [2].


best,

Charles


[2]
// Grabbing the data from the form.

if ($task == updateInfo)
 {
$activityChallenges = cs_remove_curl_up(sanitize_paranoid_string
($_POST[activityChallenges]));
 }



// change curl u to EDIT kurl u

function cs_remove_curl_up($string, $min='', $max='')
{
   $string = str_replace(curl u, EDIT kurl u, $string);
   $len = strlen($string);
   if((($min != '')  ($len  $min)) || (($max != '')  ($len 
$max)))
 return FALSE;
   return $string;
}



[1]
My host told me this:

Mod_security is restricting this and blocks all url's with C-url.
This is done because of some php worms that are spread using c-url. I
would recommend trying to work around this. It will be a major
security issue for us to allow this.

--
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

2005-10-10 Thread Jochem Maas

Charles Stuart wrote:
A student run server on my old campus used to turn off PHP for  security 
reasons - ridiculous.


Would it be possible to use XSS to call curl from a remote site? I'm  
just a beginner so that may or not make sense.


I'm not really a beginner but I don't know if that makes sense either :-S
I'm pretty sure the answer is no.



Indeed it does seem like JS is the solution - unfortunately - as it  


workaround, not solution. a new host would be a solution,
one that means you don't have to waste time coding around completely
crazy setups.

seems like their 'trap' catches any string including CURL U before I  


seems like a total bogus filter. exactly what makes 'CURL U' so evil when
passed to a php/cgi script anyway?

can str_replace the string after gathering the input with _POST.  Anyone 
disagree?


well you could check out something like:

?
$putdata = fopen( php://input , rb );
while(!feof( $putdata ))
echo fread($putdata, 4096 );
fclose($putdata);
?

or

?
echo file_get_contents('php://input');
?

or

?
echo $HTTP_RAW_POST_DATA;
?






best,

Charles



On Oct 10, 2005, at 3:12 PM, Rory Browne wrote:


I'm not completely sure, but I think they're talking shite. If curl is


I think I can smell it here too.

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



Re: [PHP] str_replace weird output

2005-06-02 Thread Andy Pieters
On Thursday 02 June 2005 09:52, [EMAIL PROTECTED] wrote:
 But if I do that :

 ?php
 $texte = 'cd' ;
 $original = array('a', 'b', 'c', 'd', 'e', 'f', 'g');
 $modif = array ('c', 'd', 'e', 'f', 'g', 'h', 'i');
 $texte = str_replace($original, $modif, $texte) ;
 echo $texte, ' br /' ;
 ?

 The result is : ih

 Why ?

You should know that, unless you tell php to limit the number of replaces, it 
will keep on replacing until it doesn't find a match anymore. 

Here is what happens:

 ?php
 $texte = 'cd' ;
 $original = array('a', 'b', 'c', 'd', 'e', 'f', 'g');
 $modif = array ('c', 'd', 'e', 'f', 'g', 'h', 'i');
 $texte = str_replace($original, $modif, $texte) ;
#after first replacement
$texte='ef'
#after 2nd replacement
$texte='gh'
#after third replacement
$texte='ih';

If you want to prevent this, tell the function that you only want 2 
replacements.  Like this:
$limite=2;
$texte=str_replace($original,$modif,$texte,$limite);

Hope this helps

With kind regards


ps: the php documentation is also available in French.  Check out: 
http://fr2.php.net/manual/fr/function.str-replace.php for more info on 
str_replace

Andy

-- 
Registered Linux User Number 379093
-- --BEGIN GEEK CODE BLOCK-
Version: 3.1
GAT/O/E$ d-(---)+ s:(+): a--(-)? C$(+++) UL$ P-(+)++
L+++$ E---(-)@ W++$ !N@ o? !K? W--(---) !O !M- V-- PS++(+++)
PE--(-) Y+ PGP++(+++) t+(++) 5-- X++ R*(+)@ !tv b-() DI(+) D+(+++) G(+)
e$@ h++(*) r--++ y--()
-- ---END GEEK CODE BLOCK--
--
Check out these few php utilities that I released
 under the GPL2 and that are meant for use with a 
 php cli binary:
 
 http://www.vlaamse-kern.com/sas/
--

--

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



Re: [PHP] str_replace on words?

2005-05-12 Thread Merlin
Duncan Hill wrote:
On Wednesday 11 May 2005 17:13, Merlin wrote:
Hi there,
I am trying to strip some words from a sentence. I tried it with
str_replace like described here:
http://www.totallyphp.co.uk/code/find_and_replace_words_in_a_text_string_us
ing_str_replace.htm
Unfortunatelly it does not work the way I want, because if I want to
replace the word in all passages containing the characters in are
replaced. For example Singapore.

You need to tokenize your input and do exact matching.  Alternately, 
preg_match / preg_replace may work with \b to specify word boundries.
Hi Duncan,
that in fact was the key and only way to get a proper result.
I found this script on the preg_replace page of php.net:
// Function highlights $words in $str
function highlight_words($str, $words) {
  if(is_array($words)) {
   foreach($words as $k = $word) {
 $pattern[$k] = /\b($word)\b/is;
 $replace[$k] = 'b\\1/b';
   }
  }
  else {
   $pattern = /\b($words)\b/is;
   $replace = 'b\\1/b';
  }
  return preg_replace($pattern,$replace,$str);
}
Which works excellent!
Thanx, Merlin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] str_replace on words?

2005-05-12 Thread James E Hicks III
Merlin wrote:
Hi there,
I am trying to strip some words from a sentence. I tried it with 
str_replace like described here:
http://www.totallyphp.co.uk/code/find_and_replace_words_in_a_text_string_using_str_replace.htm 

Unfortunatelly it does not work the way I want, because if I want to 
replace the word in all passages containing the characters in are 
replaced. For example Singapore.

Does anybody know how to do this on just words?
Thank you for any hint,
Merlin
$variable = 'I like to Sing in Singapore';
$variable = str_replace(' in ',' for ',$variable);
echo $varible;
Results should be:
I like to Sing for Singapore
James
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] str_replace on words?

2005-05-11 Thread Jay Blanchard
[snip]
Does anybody know how to do this on just words?
[/snip]

explode the string into an array of words and then apply the function to
the array value. Then implode the string into a new string.

http://www.php.net/explode
http://www.php.net/implode

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



Re: [PHP] str_replace on words?

2005-05-11 Thread Duncan Hill
On Wednesday 11 May 2005 17:13, Merlin wrote:
 Hi there,

 I am trying to strip some words from a sentence. I tried it with
 str_replace like described here:
 http://www.totallyphp.co.uk/code/find_and_replace_words_in_a_text_string_us
ing_str_replace.htm

 Unfortunatelly it does not work the way I want, because if I want to
 replace the word in all passages containing the characters in are
 replaced. For example Singapore.

You need to tokenize your input and do exact matching.  Alternately, 
preg_match / preg_replace may work with \b to specify word boundries.

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



RE: [PHP] str_replace on words?

2005-05-11 Thread Mikey
 Hi there,
 
 I am trying to strip some words from a sentence. I tried it 
 with str_replace like described here:
 http://www.totallyphp.co.uk/code/find_and_replace_words_in_a_t
 ext_string_using_str_replace.htm
 
 Unfortunatelly it does not work the way I want, because if I 
 want to replace the word in all passages containing the 
 characters in are replaced. For example Singapore.
 
 Does anybody know how to do this on just words?
 
 Thank you for any hint,
 
 Merlin

You should look into using a regular expression as these can recognise word
boundaries when matching (preg_match, preg_replace, etc).

I think this solution will apply to your other post as well.

HTH,

Mikey

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



Re: [PHP] str_replace on words?

2005-05-11 Thread Brent Baisley
I think that's a bad example you read. It doesn't describe how to  
search on a word it describes how to search on a string, which is  
what you ended up doing.
For things like this I use arrays. Assuming your words are separated  
by spaces, you can get an array of all the words by doing:
$word_list = explode(' ', $text);

Then you can cycle through each element of the array (there are a  
number of ways to do this), testing if it equals your word and replace  
it if it does.
Then put it all back together with:
$text = implode(' ', $word_list);

On May 11, 2005, at 12:13 PM, Merlin wrote:
Hi there,
I am trying to strip some words from a sentence. I tried it with  
str_replace like described here:
http://www.totallyphp.co.uk/code/ 
find_and_replace_words_in_a_text_string_using_str_replace.htm

Unfortunatelly it does not work the way I want, because if I want to  
replace the word in all passages containing the characters in are  
replaced. For example Singapore.

Does anybody know how to do this on just words?
Thank you for any hint,
Merlin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] str_replace on words?

2005-05-11 Thread tg-php
As mentioned in the making words bold thread, works aren't always separated 
by spaces.  Sometimes they end a sentence so are followed by a period or other 
punctuation.  Sometimes you have strings like and/or where they're separated 
by the forward slash, etc.

You really have to do some kind of regex expression to get this right when 
substituting whole words and not just any substring.

A thought in the exact right direction, just need to follow through with the 
rest of the thought.

-TG

= = = Original message = = =

I think that's a bad example you read. It doesn't describe how to  
search on a word it describes how to search on a string, which is  
what you ended up doing.
For things like this I use arrays. Assuming your words are separated  
by spaces, you can get an array of all the words by doing:
$word_list = explode(' ', $text);

Then you can cycle through each element of the array (there are a  
number of ways to do this), testing if it equals your word and replace  
it if it does.
Then put it all back together with:
$text = implode(' ', $word_list);

On May 11, 2005, at 12:13 PM, Merlin wrote:

 Hi there,

 I am trying to strip some words from a sentence. I tried it with  
 str_replace like described here:
 http://www.totallyphp.co.uk/code/ 
 find_and_replace_words_in_a_text_string_using_str_replace.htm

 Unfortunatelly it does not work the way I want, because if I want to  
 replace the word in all passages containing the characters in are  
 replaced. For example Singapore.

 Does anybody know how to do this on just words?

 Thank you for any hint,

 Merlin

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


-- 
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

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


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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



Re: [PHP] str_replace on words?

2005-05-11 Thread AC
I whipped this together, it should work ok. You'll want to clean it up, 
but you get the gist.

?php
/* AC Was here */
$str=I'm going to the store to buy some stuff.;
$bold=array(store,some,stuff);
function boldWord($str,$bold) {
  if(isset($str)) {
  foreach($bold as $b) {
echo $b should be b$b/b\n;
  $str = eregi_replace($b,b$b/b,$str);
  }
  $string=$str;
  return $string;
  } else {
  $string='The inputed variable $str was empty.';
  return $string;
  }
} // End function bracket

// Example usage
if(isset($str)) {
$string=boldWord($str,$bold);
echo Original: $str \n;
echo New: $string\n;
} else {
echo Variable str not set.;
}
?
--
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



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



Re: [PHP] str_replace: use multiple or array?

2004-07-30 Thread Curt Zirzow
* Thus wrote PHP Gen:
 Hi,
 I need to use a couple of str_replace's in one of my
 programs and would like to know which is more resource
 friendly:
 
 1) having multiple str_replace one after another
 
 eg:
 $text = str_replace(orange, apple, $text);
 $text = str_replace(black, white, $text);
 ...
 
 2) by using an array
 
 eg:
 $bad = array(orange, black, girl, woman,
 plant);
 $good = array(apple, white, guy, man, tree);
 $text = str_replace($bad, $good, $text);

#2

Anytime you can have the internals of php handle stuff for you the
better it most likely will be.


 
 
 Also, off topic,
 Anybody else getting a non delivery message from: 
 MAILER-DAEMON@ rotonet.rsdb.nl

I'll see what I can do about this. thanks for reminding me :)


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 or regex

2004-03-18 Thread Richard Davey
Hello Adam,

Thursday, March 18, 2004, 6:06:06 PM, you wrote:

AW Hi, I was wondering if I can get some help with either a str_replace or a
AW regex.  I have some data and it always begins with $$ but it can end with
AW any letter of the alphabet.  so sometimes its $$a and sometimes its $$b
AW and sometimes $$c all the way to $$z. $$a all the way to $$z needs to
AW be changed to a /  So is there a way to do this?  I was thinking of a
AW str_replace but since the letter always changes I'm not so sure.  Any help?

If I read that correctly, you want to replace $$ with /, yes?
In which case a str_replace will do that just fine. Ignore the final
letter of the string and just search for $$ and replace with a /.

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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



Re: [PHP] str_replace or regex

2004-03-18 Thread John W. Holmes
From: Adam Williams [EMAIL PROTECTED]

 Hi, I was wondering if I can get some help with either a str_replace or a
 regex.  I have some data and it always begins with $$ but it can end with
 any letter of the alphabet.  so sometimes its $$a and sometimes its $$b
 and sometimes $$c all the way to $$z. $$a all the way to $$z needs to
 be changed to a /  So is there a way to do this?  I was thinking of a
 str_replace but since the letter always changes I'm not so sure.  Any
help?

$output = preg_replace('/\$\$[a-z]/','/',$string);

If you wanted to use str_replace, then:

$array = array('$$a','$$b','$$c','$$d'...);
$output = str_replace($array,'/',$string);

---John Holmes...

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



Re: [PHP] str_replace or regex

2004-03-18 Thread Firman Wandayandi
eregi_replace('(\$\$)([a-z].+)', '\1z', '$$a');

Maybe i'm wrong, please crosscheck.

Regards,
Firman

- Original Message -
From: Adam Williams [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, March 19, 2004 1:06 AM
Subject: [PHP] str_replace or regex


 Hi, I was wondering if I can get some help with either a str_replace or a
 regex.  I have some data and it always begins with $$ but it can end with
 any letter of the alphabet.  so sometimes its $$a and sometimes its $$b
 and sometimes $$c all the way to $$z. $$a all the way to $$z needs to
 be changed to a /  So is there a way to do this?  I was thinking of a
 str_replace but since the letter always changes I'm not so sure.  Any
help?

 --
 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

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



Re: [PHP] str_replace to replace /n with p not having desired effect.

2004-02-19 Thread Adam Voigt
Single quotes don't work for the escape characters.
Use double quotes around the str_replace where there is a \n.



On Thu, 2004-02-19 at 10:52, Dave G wrote:
 PHP Listers,
   I am trying to use str_replace to format text taken from a MySQL
 TEXT field and make it so that it is compatible with my CSS formatting.
 Essentially, I want to ensure that new lines are replaced with p tags
 with the appropriate CSS class designation.
   The code I have created with assistance from information found
 on the web, looks like this:
 
 $charInfoCss = 'p class=content' . str_replace('\n', '/p\np
 class=content\n', $charInfo[introE]) . '/p';
 
   The output looks like this:
 p class=contentBlah blah blah blah.
 Another line of blah blah blah.
 A third line of blah blah blah./p
 
   The output I desire is this:
 p class=contentBlah blah blah blah./p
 p class=contentAnother line of blah blah blah./p
 p class=contentA third line of blah blah blah./p
 
   How do I correct my code to accomplish this?
 
   Thank you.
 
 -- 
 Yoroshiku!
 Dave G
[EMAIL PROTECTED]
-- 

Adam Voigt
[EMAIL PROTECTED]

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



Re: [PHP] str_replace to replace /n with p not having desired effect.

2004-02-19 Thread Richard Davey
Hello Dave,

Thursday, February 19, 2004, 3:52:54 PM, you wrote:

DG $charInfoCss = 'p class=content' . str_replace('\n', '/p\np
class=content\n', $charInfo[introE]) . '/p';

Double-bag it:

str_replace(\n, /p\np class=\content\\n, $charInfo[introE])

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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



RE: [PHP] str_replace to replace /n with p not having desiredeffect. [SOLVED]

2004-02-19 Thread Dave G
 From: Adam 
 Single quotes don't work for the escape characters.
 Use double quotes around the str_replace where there is a \n.
and...
 From: Richard
 Double-bag it:
 str_replace(\n, /p\np class=\content\\n, $charInfo[introE])

It's always the simplest of mistakes that one overlooks.
Thanks guys! That's done the trick.

-- 
Yoroshiku!
Dave G
[EMAIL PROTECTED]

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



Re: [PHP] str_replace not replacing

2004-02-11 Thread Richard Davey
Hello Aaron,

Wednesday, February 11, 2004, 3:00:47 PM, you wrote:

AM $section1 = file_get_contents(table_create.php);
AM str_replace($search, $replace, $section1);

You need to assign the output of str_replace to something:

$new_section = str_replace($search, $replace, $section1)

-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

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



Re: [PHP] str_replace not replacing

2004-02-11 Thread Jason Wong
On Wednesday 11 February 2004 23:00, Aaron Merrick wrote:

 My problem is, I want to replace the table name in the original file with a
 new table name before I output it to the new file. But the str_replace has
 no effect. 

[snip]

 str_replace($search, $replace, $section1);

str_replace() returns a value, use it.

-- 
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
--
/*
A bit of talcum
Is always walcum
-- Ogden Nash
*/

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



Re: [PHP] str_replace not replacing

2004-02-11 Thread Aaron Merrick
Richard,

Thank you so much. That works perfectly. I knew it had to be something
simple.

Aaron

 From: Richard Davey [EMAIL PROTECTED]
 Reply-To: Richard Davey [EMAIL PROTECTED]
 Date: Wed, 11 Feb 2004 15:04:44 +
 To: Aaron Merrick [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: Re: [PHP] str_replace not replacing
 
 Hello Aaron,
 
 Wednesday, February 11, 2004, 3:00:47 PM, you wrote:
 
 AM $section1 = file_get_contents(table_create.php);
 AM str_replace($search, $replace, $section1);
 
 You need to assign the output of str_replace to something:
 
 $new_section = str_replace($search, $replace, $section1)
 
 -- 
 Best regards,
 Richardmailto:[EMAIL PROTECTED]
 
 -- 
 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 Command

2004-02-02 Thread Jason Wong
On Tuesday 03 February 2004 00:14, Christopher J. Crane wrote:

   $StockURL =
 http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
   $StockResults = implode('', file($StockURL));
   $Rows = split(\n, $StockResults);
   foreach($Rows as $Row) { echo str_replace('',,$Row).br\n; }
   foreach($Rows as $Row) { str_replace('',,$Row); echo $Row.br\n; }

str_replace() RETURNS the replaced string. It does not alter $Row.

-- 
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
--
/*
Spiritual leadership should remain spiritual leadership and the temporal
power should not become too important in any church.
- Eleanor Roosevelt
*/

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



Re: [PHP] Str_Replace Command

2004-02-02 Thread Christopher J. Crane
Ok I got around it by the following, but now I have a new problem. I can not
get the two dimensional array working. I want to later be able to output a
variable like this $TickerData[IKN] and it will output the associated
$Price.

  $StockURL =
http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
  $StockResults = implode('', file($StockURL));
  $Rows = split(\n, $StockResults);
  foreach($Rows as $Row) {
list($Symbol, $Price) = split(,, $Row);
   $Symbol = str_replace('', , $Symbol);
   $TickerData = array($Symbol=$Ticker);
}
  print_r($TickerData);
  echo $TickerData[IKN].br\n;




Jason Wong [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Tuesday 03 February 2004 00:14, Christopher J. Crane wrote:

$StockURL =
  http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
$StockResults = implode('', file($StockURL));
$Rows = split(\n, $StockResults);
foreach($Rows as $Row) { echo str_replace('',,$Row).br\n; }
foreach($Rows as $Row) { str_replace('',,$Row); echo
$Row.br\n; }

 str_replace() RETURNS the replaced string. It does not alter $Row.

 -- 
 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
 --
 /*
 Spiritual leadership should remain spiritual leadership and the temporal
 power should not become too important in any church.
 - Eleanor Roosevelt
 */

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



Re: [PHP] Str_Replace Command

2004-02-02 Thread Jason Wong
On Tuesday 03 February 2004 00:52, Christopher J. Crane wrote:
 Ok I got around it by the following, but now I have a new problem. I can
 not get the two dimensional array working. I want to later be able to
 output a variable like this $TickerData[IKN] and it will output the
 associated $Price.

   print_r($TickerData);

So what does the above show? If it isn't what you expect, figure out *why*. 
Like how is $TickerData being assigned.

-- 
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
--
/*
We have phasers, I vote we blast 'em!
-- Bailey, The Corbomite Maneuver, stardate 1514.2
*/

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



Re: [PHP] Str_Replace Command

2004-02-02 Thread Christopher J. Crane
Well this is it and it is really got me...
Echoing out the $Symbol and $Price works just fine one row about the
$TickerData array assignment. Yet it outputs nothing.
Array ( [] = ) is what I get. If I change the line to
$TickerData = array ($Symbol = $Price); I get nothing, or the same
result. If I change the line to
$TickerData = array ('$Symbo'l = '$Price'); I get the following
Array ( [$Symbol] = $Price ) which tells me the assignment works, but it
seems like the $Symbol and $Price variable are blank when assigning to the
array. I know that they are not blank since they echoed out just fine one
line above.GRR



  $StockURL =
http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
  $StockResults = implode('', file($StockURL));
  $Rows = split(\n, $StockResults);
  foreach($Rows as $Row) {
list($Symbol, $Price) = split(,, $Row);
 $Symbol = str_replace('', , $Symbol);
echo $Symbol. - .$Price.br\n;
$TickerData = array ($Symbol = $Price);
}
  print_r($TickerData);



Jason Wong [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Tuesday 03 February 2004 00:52, Christopher J. Crane wrote:
  Ok I got around it by the following, but now I have a new problem. I can
  not get the two dimensional array working. I want to later be able to
  output a variable like this $TickerData[IKN] and it will output the
  associated $Price.

print_r($TickerData);

 So what does the above show? If it isn't what you expect, figure out
*why*.
 Like how is $TickerData being assigned.

 -- 
 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
 --
 /*
 We have phasers, I vote we blast 'em!
 -- Bailey, The Corbomite Maneuver, stardate 1514.2
 */

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



Re: [PHP] Str_Replace Command

2004-02-02 Thread Jason Wong
On Tuesday 03 February 2004 01:09, Christopher J. Crane wrote:
 Well this is it and it is really got me...
 Echoing out the $Symbol and $Price works just fine one row about the
 $TickerData array assignment. Yet it outputs nothing.
 Array ( [] = ) is what I get. If I change the line to
 $TickerData = array ($Symbol = $Price); I get nothing, or the same
 result. If I change the line to
 $TickerData = array ('$Symbo'l = '$Price'); I get the following
 Array ( [$Symbol] = $Price ) which tells me the assignment works, but it
 seems like the $Symbol and $Price variable are blank when assigning to the
 array. I know that they are not blank since they echoed out just fine one
 line above.GRR

Are you sure that the line: echo $Symbol ...
is displaying something sensible for each $Row?

You're overwriting $TickerData at each iteration of the foreach-loop thus if 
your last $Row doesn't contain something sensible neither would $TickerData.

You probably want to use this assignment instead:

  $TickerData[$Symbol] = $Price;

-- 
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
--
/*
TANSTAAFL
*/

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



Re: [PHP] Str_Replace Command

2004-02-02 Thread Matt Matijevich
snip
  $StockURL =
http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
  $StockResults = implode('', file($StockURL));
  $Rows = split(\n, $StockResults);
  foreach($Rows as $Row) {
list($Symbol, $Price) = split(,, $Row);
 $Symbol = str_replace('', , $Symbol);
echo $Symbol. - .$Price.br\n;
$TickerData = array ($Symbol = $Price);
}
  print_r($TickerData);
/snip

why not replace:
$TickerData = array ($Symbol = $Price);

that line reassigns $TickerData to a array with one element in it
everytime you call it.  The last time through your loop, $Symbol = ''
and $Price = '', so you get Array ( [] = ) when you print_r

with this:
$TickerData[$Symbol] = $Price;

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



RE: [PHP] Str_Replace Command

2004-02-02 Thread Crane, Christopher
Matt:
This worked perfect. Thank you. I didn't realize it was reassigning, I
thought it would work similar to array_push and add to the existing data. I
get it now, thanks to you.

Thanks again. I had been so frustrated I was losing my objectivity. 


Christopher J. Crane 
Network Manager - Infrastructure Services 
IKON Document Efficiency at Work 



-Original Message-
From: Matt Matijevich [mailto:[EMAIL PROTECTED] 
Sent: Monday, February 02, 2004 12:25 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [PHP] Str_Replace Command

snip
  $StockURL =
http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,dankyf=sl1e=.txt;;
  $StockResults = implode('', file($StockURL));
  $Rows = split(\n, $StockResults);
  foreach($Rows as $Row) {
list($Symbol, $Price) = split(,, $Row);  $Symbol = str_replace('',
, $Symbol);
echo $Symbol. - .$Price.br\n;
$TickerData = array ($Symbol = $Price);
}
  print_r($TickerData);
/snip

why not replace:
$TickerData = array ($Symbol = $Price);

that line reassigns $TickerData to a array with one element in it everytime
you call it.  The last time through your loop, $Symbol = ''
and $Price = '', so you get Array ( [] = ) when you print_r

with this:
$TickerData[$Symbol] = $Price;

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



Re: [PHP] str_replace and TABS

2004-01-21 Thread Matt Matijevich
[snip]
I'm using the following to replace certain characters but am having
troubles
with TABS. How do I find them?

$replacement = array(\, ,, ., !, ?,;, :,),(,\n);

Thanks
[/snip]

I think \t .  Double check with google.

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



  1   2   >