Re: [PHP] Replace a space with a newline every 2 spaces

2010-04-22 Thread Andrew Ballard
On Thu, Apr 22, 2010 at 1:29 PM, Paul Halliday paul.halli...@gmail.com wrote:
 Ex:

 This is the string and it is this long

 This is
 the string
 and it
 is this
 long

 I found some long functions to achieve this but I couldn't help but
 think that it could be done in a couple lines.

 Possible?

 Thanks.


I'm not sure it's the best method, but it didn't take long to come up with this:

?php

$string = This is the string and it is this long;

if (preg_match_all('/(?:(?:\w+\s+){2}|(?:\w+$))/', $string, $matches)) {
var_dump($matches[0]);
}


?

Andrew

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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Eddie Drapkin
On Wed, Jul 22, 2009 at 8:02 AM, rszeusrsz...@gmail.com wrote:
 Hello,

 I’m tryng to make some replacements on a string.

 Everything goês fine until the regular expression.



 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)



 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:

 screens/test_1_main.jpg



 I want it to be: screens/test_main.jpg



 Thank you





If you're trying to do a regular expression based search and replace,
you probably ought to use preg_replace instead of str_replace, as
str_replace doesn't parse regular expressions.

Try this one out, I think I got what you wanted to do:

?php

$file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', $file);

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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Ashley Sheridan
On Wed, 2009-07-22 at 13:02 +0100, rszeus wrote:
 Hello,
 
 I’m tryng to make some replacements on a string.
 
 Everything goês fine until the regular expression.
 
  
 
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 
 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)
 
  
 
 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:
 
 screens/test_1_main.jpg
 
  
 
 I want it to be: screens/test_main.jpg
 
  
 
 Thank you
 
  
 
Well, you seem to have some problems with the syntax you're using on
str_replace(). According to your script, you want to remove the
following:

7a45gfdi6icpan1jtb1j99o925- which you haven't even enclosed in quote
marks
'temp/'
’_([0-9])’- which are using weird back ticks, not quote marks

and you are trying to replace those three things with

“test”  - again, not proper quote marks

””  - not proper quote marks

Afaik, str_replace() doesn't allow for text replacement using regular
expressions, for that you'd have to use something like preg_replace()

Also, make sure your strings are correctly enclosed in quote marks, and
that the quote marks you use are actual quote marks and not the accented
'pretty' ones that are offered up by word processors, etc.

A regex which would do the job would look something like this:

^([^/]+)[^_]+\/(.+)$

That should create 2 matches, one for the initial directory and the
other for the latter part of the filename.

Thanks
Ash
www.ashleysheridan.co.uk


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



RE: [PHP] Replace in a string with regex

2009-07-22 Thread rszeus
Hi. It Works to remove the _1 but it doesn't replace 
'7a45gfdi6icpan1jtb1j99o925' for 'test'

Thank you

-Mensagem original-
De: Eddie Drapkin [mailto:oorza...@gmail.com] 
Enviada: quarta-feira, 22 de Julho de 2009 13:11
Para: rszeus
Cc: php-general@lists.php.net
Assunto: Re: [PHP] Replace in a string with regex

On Wed, Jul 22, 2009 at 8:02 AM, rszeusrsz...@gmail.com wrote:
 Hello,

 I’m tryng to make some replacements on a string.

 Everything goês fine until the regular expression.



 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)



 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:

 screens/test_1_main.jpg



 I want it to be: screens/test_main.jpg



 Thank you





If you're trying to do a regular expression based search and replace,
you probably ought to use preg_replace instead of str_replace, as
str_replace doesn't parse regular expressions.

Try this one out, I think I got what you wanted to do:

?php

$file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', $file);


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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Eddie Drapkin
On Wed, Jul 22, 2009 at 9:07 AM, rszeusrsz...@gmail.com wrote:
 Hi. It Works to remove the _1 but it doesn't replace 
 '7a45gfdi6icpan1jtb1j99o925' for 'test'

 Thank you

 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com]
 Enviada: quarta-feira, 22 de Julho de 2009 13:11
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex

 On Wed, Jul 22, 2009 at 8:02 AM, rszeusrsz...@gmail.com wrote:
 Hello,

 I’m tryng to make some replacements on a string.

 Everything goês fine until the regular expression.



 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)



 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:

 screens/test_1_main.jpg



 I want it to be: screens/test_main.jpg



 Thank you





 If you're trying to do a regular expression based search and replace,
 you probably ought to use preg_replace instead of str_replace, as
 str_replace doesn't parse regular expressions.

 Try this one out, I think I got what you wanted to do:

 ?php

 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', $file);



In the second parameter, $2 is the string you'd want to replace to
test so change '$1$2$3' to '$1test$3'.

It seems like you're having trouble with regular expressions, may I
suggest you read up on them?

http://www.regular-expressions.info/ is a pretty great free resource,
as ridiculous as the design is.

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



RE: [PHP] Replace in a string with regex

2009-07-22 Thread rszeus
Totally right on the corrections. Sorry, i did not copy paste from the source 
code, I wrote here to change to other names and wrote it bad.
It should be:
$file = 'screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg';

 echo $a =  str_replace(array('7a45gfdi6icpan1jtb1j99o925', 
'temp/',’_([0-9])’), array('test','',''), $file)

Already understand that str_replace doesn't work with regex, but not getting 
any luck making one preg_replace() to my needs.

Thank you

-Mensagem original-
De: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Enviada: quarta-feira, 22 de Julho de 2009 13:20
Para: rszeus
Cc: php-general@lists.php.net
Assunto: Re: [PHP] Replace in a string with regex

On Wed, 2009-07-22 at 13:02 +0100, rszeus wrote:
 Hello,
 
 I’m tryng to make some replacements on a string.
 
 Everything goês fine until the regular expression.
 
  
 
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 
 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)
 
  
 
 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:
 
 screens/test_1_main.jpg
 
  
 
 I want it to be: screens/test_main.jpg
 
  
 
 Thank you
 
  
 
Well, you seem to have some problems with the syntax you're using on
str_replace(). According to your script, you want to remove the
following:

7a45gfdi6icpan1jtb1j99o925- which you haven't even enclosed in quote
marks
'temp/'
’_([0-9])’- which are using weird back ticks, not quote marks

and you are trying to replace those three things with

“test”  - again, not proper quote marks

””  - not proper quote marks

Afaik, str_replace() doesn't allow for text replacement using regular
expressions, for that you'd have to use something like preg_replace()

Also, make sure your strings are correctly enclosed in quote marks, and
that the quote marks you use are actual quote marks and not the accented
'pretty' ones that are offered up by word processors, etc.

A regex which would do the job would look something like this:

^([^/]+)[^_]+\/(.+)$

That should create 2 matches, one for the initial directory and the
other for the latter part of the filename.

Thanks
Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Robert Cummings

rszeus wrote:

Hello,

I’m tryng to make some replacements on a string.

Everything goês fine until the regular expression.

 


$file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
'temp/',’_([0-9])’), array(“test”,,””), $file)

 


The idea is to remove /temp and the last _1 from the file name..but i’m only
getting this:

screens/test_1_main.jpg

 


I want it to be: screens/test_main.jpg


Sometimes it's helpful to break a problem into smaller problems:

?php

$a = str_replace( '/temp/', '/', $file );
$a = preg_replace( '#_\d+_#', '_', $a );

echo $a.\n;

?

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Robert Cummings
You can disregard this, it's wrong (I missed a part of the requirements 
:) and there's other solutions already provided (my email client is 
weird when you switch to a folder it always displays the first entry as 
the last read, so sometimes I miss that there are new posts above... I 
just switched a few weeks ago.


Cheers,
Rob.


Robert Cummings wrote:

rszeus wrote:

Hello,

I’m tryng to make some replacements on a string.

Everything goês fine until the regular expression.

 


$file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
'temp/',’_([0-9])’), array(“test”,,””), $file)

 


The idea is to remove /temp and the last _1 from the file name..but i’m only
getting this:

screens/test_1_main.jpg

 


I want it to be: screens/test_main.jpg


Sometimes it's helpful to break a problem into smaller problems:

?php

 $a = str_replace( '/temp/', '/', $file );
 $a = preg_replace( '#_\d+_#', '_', $a );

 echo $a.\n;

?

Cheers,
Rob.


--
http://www.interjinn.com
Application and Templating Framework for PHP

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



RE: [PHP] Replace in a string with regex

2009-07-22 Thread rszeus

Thank you.

What about instead test i want to insert a variable ?
Like 
$id = 30;
$file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$id$3', $file);
I am confusing  and '. 

Thank you
 

-Mensagem original-
De: Eddie Drapkin [mailto:oorza...@gmail.com] 
Enviada: quarta-feira, 22 de Julho de 2009 14:12
Para: rszeus
Cc: php-general@lists.php.net
Assunto: Re: [PHP] Replace in a string with regex

On Wed, Jul 22, 2009 at 9:07 AM, rszeusrsz...@gmail.com wrote:
 Hi. It Works to remove the _1 but it doesn't replace 
 '7a45gfdi6icpan1jtb1j99o925' for 'test'

 Thank you

 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com]
 Enviada: quarta-feira, 22 de Julho de 2009 13:11
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex

 On Wed, Jul 22, 2009 at 8:02 AM, rszeusrsz...@gmail.com wrote:
 Hello,

 I’m tryng to make some replacements on a string.

 Everything goês fine until the regular expression.



 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)



 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:

 screens/test_1_main.jpg



 I want it to be: screens/test_main.jpg



 Thank you





 If you're trying to do a regular expression based search and replace,
 you probably ought to use preg_replace instead of str_replace, as
 str_replace doesn't parse regular expressions.

 Try this one out, I think I got what you wanted to do:

 ?php

 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', $file);



In the second parameter, $2 is the string you'd want to replace to
test so change '$1$2$3' to '$1test$3'.

It seems like you're having trouble with regular expressions, may I
suggest you read up on them?

http://www.regular-expressions.info/ is a pretty great free resource,
as ridiculous as the design is.


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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Jim Lucas
rszeus wrote:
 Thank you.
 
 What about instead test i want to insert a variable ?
 Like 
 $id = 30;
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$id$3', $file);

Sure that can be done.  But you will need to change the second argument
to have double quotes so it will be parsed by PHP.

Then I would surround YOUR variable with curly brackets to separate it
from the rest.

echo preg_replace('#(screens/)temp/.+?_1(_main\.jpg)#',
  $1{$id}$3,
  $file);

 I am confusing  and '. 
 
 Thank you
  
 
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com] 
 Enviada: quarta-feira, 22 de Julho de 2009 14:12
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
 
 On Wed, Jul 22, 2009 at 9:07 AM, rszeusrsz...@gmail.com wrote:
 Hi. It Works to remove the _1 but it doesn't replace 
 '7a45gfdi6icpan1jtb1j99o925' for 'test'

 Thank you

 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com]
 Enviada: quarta-feira, 22 de Julho de 2009 13:11
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex

 On Wed, Jul 22, 2009 at 8:02 AM, rszeusrsz...@gmail.com wrote:
 Hello,

 I’m tryng to make some replacements on a string.

 Everything goês fine until the regular expression.



 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)



 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:

 screens/test_1_main.jpg



 I want it to be: screens/test_main.jpg



 Thank you




 If you're trying to do a regular expression based search and replace,
 you probably ought to use preg_replace instead of str_replace, as
 str_replace doesn't parse regular expressions.

 Try this one out, I think I got what you wanted to do:

 ?php

 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;

 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', $file);


 
 In the second parameter, $2 is the string you'd want to replace to
 test so change '$1$2$3' to '$1test$3'.
 
 It seems like you're having trouble with regular expressions, may I
 suggest you read up on them?
 
 http://www.regular-expressions.info/ is a pretty great free resource,
 as ridiculous as the design is.
 
 



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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Ashley Sheridan
On Wed, 2009-07-22 at 07:54 -0700, Jim Lucas wrote:
 rszeus wrote:
  Thank you.
  
  What about instead test i want to insert a variable ?
  Like 
  $id = 30;
  $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
  echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$id$3', $file);
 
 Sure that can be done.  But you will need to change the second argument
 to have double quotes so it will be parsed by PHP.
 
 Then I would surround YOUR variable with curly brackets to separate it
 from the rest.
 
 echo preg_replace('#(screens/)temp/.+?_1(_main\.jpg)#',
   $1{$id}$3,
   $file);
 
  I am confusing  and '. 
  
  Thank you
   
  
  -Mensagem original-
  De: Eddie Drapkin [mailto:oorza...@gmail.com] 
  Enviada: quarta-feira, 22 de Julho de 2009 14:12
  Para: rszeus
  Cc: php-general@lists.php.net
  Assunto: Re: [PHP] Replace in a string with regex
  
  On Wed, Jul 22, 2009 at 9:07 AM, rszeusrsz...@gmail.com wrote:
  Hi. It Works to remove the _1 but it doesn't replace 
  '7a45gfdi6icpan1jtb1j99o925' for 'test'
 
  Thank you
 
  -Mensagem original-
  De: Eddie Drapkin [mailto:oorza...@gmail.com]
  Enviada: quarta-feira, 22 de Julho de 2009 13:11
  Para: rszeus
  Cc: php-general@lists.php.net
  Assunto: Re: [PHP] Replace in a string with regex
 
  On Wed, Jul 22, 2009 at 8:02 AM, rszeusrsz...@gmail.com wrote:
  Hello,
 
  I’m tryng to make some replacements on a string.
 
  Everything goês fine until the regular expression.
 
 
 
  $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 
  echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
  'temp/',’_([0-9])’), array(“test”,,””), $file)
 
 
 
  The idea is to remove /temp and the last _1 from the file name..but i’m 
  only
  getting this:
 
  screens/test_1_main.jpg
 
 
 
  I want it to be: screens/test_main.jpg
 
 
 
  Thank you
 
 
 
 
  If you're trying to do a regular expression based search and replace,
  you probably ought to use preg_replace instead of str_replace, as
  str_replace doesn't parse regular expressions.
 
  Try this one out, I think I got what you wanted to do:
 
  ?php
 
  $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 
  echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', $file);
 
 
  
  In the second parameter, $2 is the string you'd want to replace to
  test so change '$1$2$3' to '$1test$3'.
  
  It seems like you're having trouble with regular expressions, may I
  suggest you read up on them?
  
  http://www.regular-expressions.info/ is a pretty great free resource,
  as ridiculous as the design is.
  
  
 
 
 
I tested this, with the double quotes and the curly braces around the
middle argument (to avoid PHP getting confused) and it didn't recognise
the matches by the numbered $1, $3, etc. I know I'm not the op who asked
the original question, but it might help him/her?

Thanks
Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Eddie Drapkin
On Wed, Jul 22, 2009 at 11:01 AM, Ashley
Sheridana...@ashleysheridan.co.uk wrote:
 On Wed, 2009-07-22 at 07:54 -0700, Jim Lucas wrote:
 rszeus wrote:
  Thank you.
 
  What about instead test i want to insert a variable ?
  Like
  $id = 30;
  $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
  echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$id$3', 
  $file);

 Sure that can be done.  But you will need to change the second argument
 to have double quotes so it will be parsed by PHP.

 Then I would surround YOUR variable with curly brackets to separate it
 from the rest.

 echo preg_replace('#(screens/)temp/.+?_1(_main\.jpg)#',
                   $1{$id}$3,
                   $file);

  I am confusing  and '.
 
  Thank you
 
 
  -Mensagem original-
  De: Eddie Drapkin [mailto:oorza...@gmail.com]
  Enviada: quarta-feira, 22 de Julho de 2009 14:12
  Para: rszeus
  Cc: php-general@lists.php.net
  Assunto: Re: [PHP] Replace in a string with regex
 
  On Wed, Jul 22, 2009 at 9:07 AM, rszeusrsz...@gmail.com wrote:
  Hi. It Works to remove the _1 but it doesn't replace 
  '7a45gfdi6icpan1jtb1j99o925' for 'test'
 
  Thank you
 
  -Mensagem original-
  De: Eddie Drapkin [mailto:oorza...@gmail.com]
  Enviada: quarta-feira, 22 de Julho de 2009 13:11
  Para: rszeus
  Cc: php-general@lists.php.net
  Assunto: Re: [PHP] Replace in a string with regex
 
  On Wed, Jul 22, 2009 at 8:02 AM, rszeusrsz...@gmail.com wrote:
  Hello,
 
  I’m tryng to make some replacements on a string.
 
  Everything goês fine until the regular expression.
 
 
 
  $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 
  echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
  'temp/',’_([0-9])’), array(“test”,,””), $file)
 
 
 
  The idea is to remove /temp and the last _1 from the file name..but i’m 
  only
  getting this:
 
  screens/test_1_main.jpg
 
 
 
  I want it to be: screens/test_main.jpg
 
 
 
  Thank you
 
 
 
 
  If you're trying to do a regular expression based search and replace,
  you probably ought to use preg_replace instead of str_replace, as
  str_replace doesn't parse regular expressions.
 
  Try this one out, I think I got what you wanted to do:
 
  ?php
 
  $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 
  echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', 
  $file);
 
 
 
  In the second parameter, $2 is the string you'd want to replace to
  test so change '$1$2$3' to '$1test$3'.
 
  It seems like you're having trouble with regular expressions, may I
  suggest you read up on them?
 
  http://www.regular-expressions.info/ is a pretty great free resource,
  as ridiculous as the design is.
 
 



 I tested this, with the double quotes and the curly braces around the
 middle argument (to avoid PHP getting confused) and it didn't recognise
 the matches by the numbered $1, $3, etc. I know I'm not the op who asked
 the original question, but it might help him/her?

 Thanks
 Ash
 www.ashleysheridan.co.uk



To avoid confusion, rather than something like
$1{$id}$3
Which looks really indecipherable, I'd definitely think something like
'$1' . $id . '$3'
is a lot easier to read and understand what's going on by immediately
looking at it.

As an added bonus, it'll definitely work ;)

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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Andrew Ballard
On Wed, Jul 22, 2009 at 11:01 AM, Ashley
Sheridana...@ashleysheridan.co.uk wrote:
 On Wed, 2009-07-22 at 07:54 -0700, Jim Lucas wrote:
 Sure that can be done.  But you will need to change the second argument
 to have double quotes so it will be parsed by PHP.

 Then I would surround YOUR variable with curly brackets to separate it
 from the rest.

 echo preg_replace('#(screens/)temp/.+?_1(_main\.jpg)#',
                   $1{$id}$3,
                   $file);

 I tested this, with the double quotes and the curly braces around the
 middle argument (to avoid PHP getting confused) and it didn't recognise
 the matches by the numbered $1, $3, etc. I know I'm not the op who asked
 the original question, but it might help him/her?

 Thanks
 Ash
 www.ashleysheridan.co.uk

Don't you also have to escape the $'s for the matches since it's in
double quotes?

\$1{$id}\$3

Andrew

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



RE: [PHP] Replace in a string with regex

2009-07-22 Thread rszeus
Hi, 
It doens't work.
I get 0_main.jpg if I do that..
I don't undestand the point of $1 $2 and $3..
In preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', what will be $1 and $2 
and $3 ?
$  I already knwo it's the (.+?) but the others didnt' get it.

Thank you...

-Mensagem original-
De: Eddie Drapkin [mailto:oorza...@gmail.com] 
Enviada: quarta-feira, 22 de Julho de 2009 16:03
Para: a...@ashleysheridan.co.uk
Cc: Jim Lucas; rszeus; php-general@lists.php.net
Assunto: Re: [PHP] Replace in a string with regex

On Wed, Jul 22, 2009 at 11:01 AM, Ashley
Sheridana...@ashleysheridan.co.uk wrote:
 On Wed, 2009-07-22 at 07:54 -0700, Jim Lucas wrote:
 rszeus wrote:
  Thank you.
 
  What about instead test i want to insert a variable ?
  Like
  $id = 30;
  $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
  echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$id$3', 
  $file);

 Sure that can be done.  But you will need to change the second argument
 to have double quotes so it will be parsed by PHP.

 Then I would surround YOUR variable with curly brackets to separate it
 from the rest.

 echo preg_replace('#(screens/)temp/.+?_1(_main\.jpg)#',
   $1{$id}$3,
   $file);

  I am confusing  and '.
 
  Thank you
 
 
  -Mensagem original-
  De: Eddie Drapkin [mailto:oorza...@gmail.com]
  Enviada: quarta-feira, 22 de Julho de 2009 14:12
  Para: rszeus
  Cc: php-general@lists.php.net
  Assunto: Re: [PHP] Replace in a string with regex
 
  On Wed, Jul 22, 2009 at 9:07 AM, rszeusrsz...@gmail.com wrote:
  Hi. It Works to remove the _1 but it doesn't replace 
  '7a45gfdi6icpan1jtb1j99o925' for 'test'
 
  Thank you
 
  -Mensagem original-
  De: Eddie Drapkin [mailto:oorza...@gmail.com]
  Enviada: quarta-feira, 22 de Julho de 2009 13:11
  Para: rszeus
  Cc: php-general@lists.php.net
  Assunto: Re: [PHP] Replace in a string with regex
 
  On Wed, Jul 22, 2009 at 8:02 AM, rszeusrsz...@gmail.com wrote:
  Hello,
 
  I’m tryng to make some replacements on a string.
 
  Everything goês fine until the regular expression.
 
 
 
  $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 
  echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
  'temp/',’_([0-9])’), array(“test”,,””), $file)
 
 
 
  The idea is to remove /temp and the last _1 from the file name..but i’m 
  only
  getting this:
 
  screens/test_1_main.jpg
 
 
 
  I want it to be: screens/test_main.jpg
 
 
 
  Thank you
 
 
 
 
  If you're trying to do a regular expression based search and replace,
  you probably ought to use preg_replace instead of str_replace, as
  str_replace doesn't parse regular expressions.
 
  Try this one out, I think I got what you wanted to do:
 
  ?php
 
  $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 
  echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', 
  $file);
 
 
 
  In the second parameter, $2 is the string you'd want to replace to
  test so change '$1$2$3' to '$1test$3'.
 
  It seems like you're having trouble with regular expressions, may I
  suggest you read up on them?
 
  http://www.regular-expressions.info/ is a pretty great free resource,
  as ridiculous as the design is.
 
 



 I tested this, with the double quotes and the curly braces around the
 middle argument (to avoid PHP getting confused) and it didn't recognise
 the matches by the numbered $1, $3, etc. I know I'm not the op who asked
 the original question, but it might help him/her?

 Thanks
 Ash
 www.ashleysheridan.co.uk



To avoid confusion, rather than something like
$1{$id}$3
Which looks really indecipherable, I'd definitely think something like
'$1' . $id . '$3'
is a lot easier to read and understand what's going on by immediately
looking at it.

As an added bonus, it'll definitely work ;)


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



Re: [PHP] Replace in a string with regex

2009-07-22 Thread Jim Lucas
rszeus wrote:
 Thank you. I undestand now.
 
 Anh it’s already workyng the replacemente with letteres. Bu if the variabele 
 is a number it doens’t work. Any ideas ?
 
  
 
 $file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg;
 
  
 
 $id = '70';
 
  echo preg_replace('#(Iscreen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);
 

You have a great big capital I in there...  Try removing that and see
what happens.


 I get 0
 
  
 
  
 
 $id = 'test';
 
  echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);
 
 I get screen/test
 
  
 
 Any ideas ?
 
  
 
 Thank you
 
  
 
 De: Kyle Smith [mailto:kyle.sm...@inforonics.com] 
 Enviada: quarta-feira, 22 de Julho de 2009 17:22
 Para: rszeus
 Cc: 'Eddie Drapkin'; a...@ashleysheridan.co.uk; 'Jim Lucas'; 
 php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
 
  
 
 The first match inside () is assigned to $1, the second is assigned to $2, 
 and so on.
 
 rszeus wrote: 
 
 Hi, 
 It doens't work.
 I get 0_main.jpg if I do that..
 I don't undestand the point of $1 $2 and $3..
 In preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', what will be $1 and 
 $2 and $3 ?
 $  I already knwo it's the (.+?) but the others didnt' get it.
  
 Thank you...
  
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com] 
 Enviada: quarta-feira, 22 de Julho de 2009 16:03
 Para: a...@ashleysheridan.co.uk
 Cc: Jim Lucas; rszeus; php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
  
 On Wed, Jul 22, 2009 at 11:01 AM, Ashley
 Sheridan mailto:a...@ashleysheridan.co.uk a...@ashleysheridan.co.uk wrote:
   
 
 On Wed, 2009-07-22 at 07:54 -0700, Jim Lucas wrote:
 
 
 rszeus wrote:
   
 
 Thank you.
  
 What about instead test i want to insert a variable ?
 Like
 $id = 30;
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$id$3', $file);
 
 
 Sure that can be done.  But you will need to change the second argument
 to have double quotes so it will be parsed by PHP.
  
 Then I would surround YOUR variable with curly brackets to separate it
 from the rest.
  
 echo preg_replace('#(screens/)temp/.+?_1(_main\.jpg)#',
   $1{$id}$3,
   $file);
  
   
 
 I am confusing  and '.
  
 Thank you
  
  
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com]
 Enviada: quarta-feira, 22 de Julho de 2009 14:12
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
  
 On Wed, Jul 22, 2009 at 9:07 AM, rszeus mailto:rsz...@gmail.com 
 rsz...@gmail.com wrote:
 
 
 Hi. It Works to remove the _1 but it doesn't replace 
 '7a45gfdi6icpan1jtb1j99o925' for 'test'
  
 Thank you
  
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com]
 Enviada: quarta-feira, 22 de Julho de 2009 13:11
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
  
 On Wed, Jul 22, 2009 at 8:02 AM, rszeus mailto:rsz...@gmail.com 
 rsz...@gmail.com wrote:
   
 
 Hello,
  
 I’m tryng to make some replacements on a string.
  
 Everything goês fine until the regular expression.
  
  
  
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
  
 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)
  
  
  
 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:
  
 screens/test_1_main.jpg
  
  
  
 I want it to be: screens/test_main.jpg
  
  
  
 Thank you
  
  
  
  
 
 
 If you're trying to do a regular expression based search and replace,
 you probably ought to use preg_replace instead of str_replace, as
 str_replace doesn't parse regular expressions.
  
 Try this one out, I think I got what you wanted to do:
  
 ?php
  
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
  
 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', $file);
  
  
   
 
 In the second parameter, $2 is the string you'd want to replace to
 test so change '$1$2$3' to '$1test$3'.
  
 It seems like you're having trouble with regular expressions, may I
 suggest you read up on them?
  
 http://www.regular-expressions.info/ is a pretty great free resource,
 as ridiculous as the design is.
  
  
 
 
  
  
   
 
 I tested this, with the double quotes and the curly braces around the
 middle argument (to avoid PHP getting confused) and it didn't recognise
 the matches by the numbered $1, $3, etc. I know I'm not the op who asked
 the original question, but it might help him/her?
  
 Thanks
 Ash
 www.ashleysheridan.co.uk
  
  
 
 
  
 To avoid confusion, rather than something like
 $1{$id}$3
 Which looks really indecipherable, I'd definitely think something like
 '$1' . $id . '$3'
 is a lot easier to read and understand what's going on by immediately
 looking at it.
  
 As an added

RE: [PHP] Replace in a string with regex

2009-07-22 Thread rszeus
No, sory, my bad typing. It's not the problem..
I have the same on both caxses, only chnage the variable $id 
 $file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg 
 $id = '70';
 echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);
 Get: 0
 
file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg;
$id = test;
echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);

Get: screen/test

What is wrong with having na integer on the var ?

Thank you

-Mensagem original-
De: Jim Lucas [mailto:li...@cmsws.com] 
Enviada: quarta-feira, 22 de Julho de 2009 18:44
Para: rszeus
Cc: 'Kyle Smith'; 'Eddie Drapkin'; a...@ashleysheridan.co.uk; 
php-general@lists.php.net
Assunto: Re: [PHP] Replace in a string with regex

rszeus wrote:
 Thank you. I undestand now.
 
 Anh it’s already workyng the replacemente with letteres. Bu if the variabele 
 is a number it doens’t work. Any ideas ?
 
  
 
 $file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg;
 
  
 
 $id = '70';
 
  echo preg_replace('#(Iscreen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);
 

You have a great big capital I in there...  Try removing that and see
what happens.


 I get 0
 
  
 
  
 
 $id = 'test';
 
  echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);
 
 I get screen/test
 
  
 
 Any ideas ?
 
  
 
 Thank you
 
  
 
 De: Kyle Smith [mailto:kyle.sm...@inforonics.com] 
 Enviada: quarta-feira, 22 de Julho de 2009 17:22
 Para: rszeus
 Cc: 'Eddie Drapkin'; a...@ashleysheridan.co.uk; 'Jim Lucas'; 
 php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
 
  
 
 The first match inside () is assigned to $1, the second is assigned to $2, 
 and so on.
 
 rszeus wrote: 
 
 Hi, 
 It doens't work.
 I get 0_main.jpg if I do that..
 I don't undestand the point of $1 $2 and $3..
 In preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', what will be $1 and 
 $2 and $3 ?
 $  I already knwo it's the (.+?) but the others didnt' get it.
  
 Thank you...
  
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com] 
 Enviada: quarta-feira, 22 de Julho de 2009 16:03
 Para: a...@ashleysheridan.co.uk
 Cc: Jim Lucas; rszeus; php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
  
 On Wed, Jul 22, 2009 at 11:01 AM, Ashley
 Sheridan mailto:a...@ashleysheridan.co.uk a...@ashleysheridan.co.uk wrote:
   
 
 On Wed, 2009-07-22 at 07:54 -0700, Jim Lucas wrote:
 
 
 rszeus wrote:
   
 
 Thank you.
  
 What about instead test i want to insert a variable ?
 Like
 $id = 30;
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$id$3', $file);
 
 
 Sure that can be done.  But you will need to change the second argument
 to have double quotes so it will be parsed by PHP.
  
 Then I would surround YOUR variable with curly brackets to separate it
 from the rest.
  
 echo preg_replace('#(screens/)temp/.+?_1(_main\.jpg)#',
   $1{$id}$3,
   $file);
  
   
 
 I am confusing  and '.
  
 Thank you
  
  
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com]
 Enviada: quarta-feira, 22 de Julho de 2009 14:12
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
  
 On Wed, Jul 22, 2009 at 9:07 AM, rszeus mailto:rsz...@gmail.com 
 rsz...@gmail.com wrote:
 
 
 Hi. It Works to remove the _1 but it doesn't replace 
 '7a45gfdi6icpan1jtb1j99o925' for 'test'
  
 Thank you
  
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com]
 Enviada: quarta-feira, 22 de Julho de 2009 13:11
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
  
 On Wed, Jul 22, 2009 at 8:02 AM, rszeus mailto:rsz...@gmail.com 
 rsz...@gmail.com wrote:
   
 
 Hello,
  
 I’m tryng to make some replacements on a string.
  
 Everything goês fine until the regular expression.
  
  
  
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
  
 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)
  
  
  
 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:
  
 screens/test_1_main.jpg
  
  
  
 I want it to be: screens/test_main.jpg
  
  
  
 Thank you
  
  
  
  
 
 
 If you're trying to do a regular expression based search and replace,
 you probably ought to use preg_replace instead of str_replace, as
 str_replace doesn't parse regular expressions.
  
 Try this one out, I think I got what you wanted to do:
  
 ?php
  
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
  
 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', $file);
  
  
   
 
 In the second parameter, $2 is the string you'd want to replace to
 test so change '$1$2$3' to '$1test$3'.
  
 It seems like you're having trouble with regular

Re: [PHP] Replace in a string with regex

2009-07-22 Thread Jim Lucas
rszeus wrote:
 No, sory, my bad typing. It's not the problem..
 I have the same on both caxses, only chnage the variable $id 
  $file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg 
  $id = '70';
  echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);
  Get: 0
  
 file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg;
 $id = test;

Well, here you are trying to use a constant called test to set your
variable $id.  I would try surrounding test with single or double quotes

 echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);
 
 Get: screen/test
 
 What is wrong with having na integer on the var ?
 
 Thank you
 
 -Mensagem original-
 De: Jim Lucas [mailto:li...@cmsws.com] 
 Enviada: quarta-feira, 22 de Julho de 2009 18:44
 Para: rszeus
 Cc: 'Kyle Smith'; 'Eddie Drapkin'; a...@ashleysheridan.co.uk; 
 php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
 
 rszeus wrote:
 Thank you. I undestand now.

 Anh it’s already workyng the replacemente with letteres. Bu if the variabele 
 is a number it doens’t work. Any ideas ?

  

 $file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg;

  

 $id = '70';

  echo preg_replace('#(Iscreen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);

 
 You have a great big capital I in there...  Try removing that and see
 what happens.
 
 
 I get 0

  

  

 $id = 'test';

  echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,  $file);

 I get screen/test

  

 Any ideas ?

  

 Thank you

  

 De: Kyle Smith [mailto:kyle.sm...@inforonics.com] 
 Enviada: quarta-feira, 22 de Julho de 2009 17:22
 Para: rszeus
 Cc: 'Eddie Drapkin'; a...@ashleysheridan.co.uk; 'Jim Lucas'; 
 php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex

  

 The first match inside () is assigned to $1, the second is assigned to $2, 
 and so on.

 rszeus wrote: 

 Hi, 
 It doens't work.
 I get 0_main.jpg if I do that..
 I don't undestand the point of $1 $2 and $3..
 In preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', what will be $1 and 
 $2 and $3 ?
 $  I already knwo it's the (.+?) but the others didnt' get it.
  
 Thank you...
  
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com] 
 Enviada: quarta-feira, 22 de Julho de 2009 16:03
 Para: a...@ashleysheridan.co.uk
 Cc: Jim Lucas; rszeus; php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
  
 On Wed, Jul 22, 2009 at 11:01 AM, Ashley
 Sheridan mailto:a...@ashleysheridan.co.uk a...@ashleysheridan.co.uk 
 wrote:
   

 On Wed, 2009-07-22 at 07:54 -0700, Jim Lucas wrote:
 

 rszeus wrote:
   

 Thank you.
  
 What about instead test i want to insert a variable ?
 Like
 $id = 30;
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$id$3', $file);
 

 Sure that can be done.  But you will need to change the second argument
 to have double quotes so it will be parsed by PHP.
  
 Then I would surround YOUR variable with curly brackets to separate it
 from the rest.
  
 echo preg_replace('#(screens/)temp/.+?_1(_main\.jpg)#',
   $1{$id}$3,
   $file);
  
   

 I am confusing  and '.
  
 Thank you
  
  
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com]
 Enviada: quarta-feira, 22 de Julho de 2009 14:12
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
  
 On Wed, Jul 22, 2009 at 9:07 AM, rszeus mailto:rsz...@gmail.com 
 rsz...@gmail.com wrote:
 

 Hi. It Works to remove the _1 but it doesn't replace 
 '7a45gfdi6icpan1jtb1j99o925' for 'test'
  
 Thank you
  
 -Mensagem original-
 De: Eddie Drapkin [mailto:oorza...@gmail.com]
 Enviada: quarta-feira, 22 de Julho de 2009 13:11
 Para: rszeus
 Cc: php-general@lists.php.net
 Assunto: Re: [PHP] Replace in a string with regex
  
 On Wed, Jul 22, 2009 at 8:02 AM, rszeus mailto:rsz...@gmail.com 
 rsz...@gmail.com wrote:
   

 Hello,
  
 I’m tryng to make some replacements on a string.
  
 Everything goês fine until the regular expression.
  
  
  
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
  
 echo $a =  str_replace(array(7a45gfdi6icpan1jtb1j99o925,
 'temp/',’_([0-9])’), array(“test”,,””), $file)
  
  
  
 The idea is to remove /temp and the last _1 from the file name..but i’m only
 getting this:
  
 screens/test_1_main.jpg
  
  
  
 I want it to be: screens/test_main.jpg
  
  
  
 Thank you
  
  
  
  
 

 If you're trying to do a regular expression based search and replace,
 you probably ought to use preg_replace instead of str_replace, as
 str_replace doesn't parse regular expressions.
  
 Try this one out, I think I got what you wanted to do:
  
 ?php
  
 $file = screens/temp/7a45gfdi6icpan1jtb1j99o925_1_main.jpg;
  
 echo preg_replace('#(screens/)temp/(.+?)_1(_main\.jpg)#', '$1$2$3', $file

RE: [PHP] Replace in a string with regex

2009-07-22 Thread Ford, Mike
 -Original Message-
 From: rszeus [mailto:rsz...@gmail.com]
 Sent: 22 July 2009 19:23
 To: 'Jim Lucas'
 Cc: 'Kyle Smith'; 'Eddie Drapkin'; a...@ashleysheridan.co.uk; php-
 gene...@lists.php.net
 Subject: RE: [PHP] Replace in a string with regex
 
 No, sory, my bad typing. It's not the problem..
 I have the same on both caxses, only chnage the variable $id
  $file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg
  $id = '70';
  echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,
 $file);
  Get: 0
 
 file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg;
 $id = test;
 echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,
 $file);
 
 Get: screen/test
 
 What is wrong with having na integer on the var ?

Well, the problem here is that when you concatenate $id containing 70 on to 
'$1', you effectively end up with '$170' -- which the manual page at 
http://php.net/preg-replace makes clear is ambiguous, but is likely to be 
treated as $17 followed by a zero, rather than $1 followed by 70. Since $17 
doesn't exist (as you don't have that many capturing subpatterns in your 
pattern!), it is taken to be the null string -- leaving just the left over 0 as 
the result of the replacement. QED.

The workaround for this is also given on the page referenced above, which is to 
make your replacement be '${1}'.$id.

Incidentally, I don't really see the need for the $1, or the equivalent 
parentheses in the pattern -- since a fixed string is involved, why not just 
use it directly in both places? Like this:

   preg_replace('#screen/temp/(.+?)_1(.+?\.jpg)#', 'screen/'.$id, $file);

which completely sidesteps the problem.

Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730




To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm


RE: [PHP] Replace in a string with regex

2009-07-22 Thread rszeus
Thank you very much!
Understand. And it Works very well now.

Cheers

-Mensagem original-
De: Ford, Mike [mailto:m.f...@leedsmet.ac.uk] 
Enviada: quinta-feira, 23 de Julho de 2009 00:04
Para: php-general@lists.php.net
Assunto: RE: [PHP] Replace in a string with regex

 -Original Message-
 From: rszeus [mailto:rsz...@gmail.com]
 Sent: 22 July 2009 19:23
 To: 'Jim Lucas'
 Cc: 'Kyle Smith'; 'Eddie Drapkin'; a...@ashleysheridan.co.uk; php-
 gene...@lists.php.net
 Subject: RE: [PHP] Replace in a string with regex
 
 No, sory, my bad typing. It's not the problem..
 I have the same on both caxses, only chnage the variable $id
  $file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg
  $id = '70';
  echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,
 $file);
  Get: 0
 
 file = screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg;
 $id = test;
 echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,
 $file);
 
 Get: screen/test
 
 What is wrong with having na integer on the var ?

Well, the problem here is that when you concatenate $id containing 70 on to 
'$1', you effectively end up with '$170' -- which the manual page at 
http://php.net/preg-replace makes clear is ambiguous, but is likely to be 
treated as $17 followed by a zero, rather than $1 followed by 70. Since $17 
doesn't exist (as you don't have that many capturing subpatterns in your 
pattern!), it is taken to be the null string -- leaving just the left over 0 as 
the result of the replacement. QED.

The workaround for this is also given on the page referenced above, which is to 
make your replacement be '${1}'.$id.

Incidentally, I don't really see the need for the $1, or the equivalent 
parentheses in the pattern -- since a fixed string is involved, why not just 
use it directly in both places? Like this:

   preg_replace('#screen/temp/(.+?)_1(.+?\.jpg)#', 'screen/'.$id, $file);

which completely sidesteps the problem.

Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730




To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm


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



Re: [PHP] Replace/Update record in dbase using dbase_replace_record()

2007-07-02 Thread Jochem Maas
Rahul Sitaram Johari wrote:
 Ave,
 
 Can¹t figure this one out. I¹m using the dbase_replace_record() function to
 replace a record in a dbase (.dbf) database. I just want to replace the
 value of one of the fields with another value. This is my code:
 
 $db = dbase_open(CRUMBS.DBF, 2) or die(Fatal Error: Could not open
 database!);
 if ($db) {
   $record_numbers = dbase_numrecords($db);
   for ($i = 1; $i = $record_numbers; $i++) {
  $row = dbase_get_record_with_names($db, $i);
  if ($row['PHONE'] == $thekey) {
   print_r($row);
   $row['A'] == F;
   dbase_replace_record($db, $row, 1);
 }
   }
 }
 dbase_close($db);
 
 Basically I have a database called ³CRUMBS.DBF², and the record where PHONE
 = $thekey, I want to replace the value of the field ³A² with ³F². I keep
 getting the error: ³Wrong number of fields specified².
 I have over 60 fields in each row ­ and I just want to replace the value of
 the field ³A². 
 
 Any suggestions?

get a big jar of 'clue'. as in learn to investigate and read ...

not having ever used these functions here are my hypotheses based on 5 seconds 
of
investigation and reading:

1. dbase_get_record_with_names() gives a assoc. array - it may also have
fields as indexed items in that array (like other DB extensions often do) ergo 
double
the fields that you want.

2. quoting the following page: http://php.net/dbase_get_record_with_names

Return Values
An associative array with the record. This will also include a key named 
deleted which is set to 1 if the record has
been marked for deletion

so dbase_replace_record() is possibly seeing 'deleted' as a extra erranous 
field.

3. maybe looking at and comparing the output of print_r($row), 
dbase_get_record_with_names($db, $i)
and dbase_get_record($db, $i) might tell you something;

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



Re: [PHP] replace single and double quotes

2006-08-30 Thread Jochem Maas
Rafael Mora wrote:
 Hi!
 
 i want to send a file or output stream in a .php, but first compress it, I
 tryed the example to compress files but how do i do to send as answer to
 the
 http request??

trye the other example


 
 Rafa
 

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



Re: [PHP] replace single and double quotes

2006-08-29 Thread afan
since I had something similar as a problem, let m etry to anser ang see
did I get it correct :)

first, and most important: never store in DB row submitted string

$act_extra = mysql_real_escape_string($_POST[editextra]);
$act_extra_fr = mysql_real_escape_string($_POST[editextrafr])
$act_id = mysql_real_escape_string($_POST[editid]);

then:
$sqledit = 
update activities
set act_extra='.$act_extra.',
act_extra_fr = '.$act_extra_fr.'
where act_id = '.$act_id.';

to check:
echo $sqledit;

it should work now.

hope this helped.

-afan



 This is the code is use to insert/update text into a database field:

 $sqledit=update activities set act_extra='$_POST[editextra]',
 act_extra_fr='$_POST[editextrafr]' where act_id=$_POST[editid];

 Now both $_POST[editextra] and $_POST[editextrafr] can contain single or
 double quotes.
 So the query almost always gives me an error.

 I know I have to replace  with quot, but I do not know how to replace
 the
 single quote so it is shown as a single quote on a webpage when I get it
 from the database

 I have been looking into str_replace and preg_replace. But what I really
 need is a solution that 'replaces' single quotes, double quotes en curly
 quotes so I tackle all possible problems and the same text as it was
 inputed
 in the textarea is shown on the webpage.

 Thx in advance

 --
 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] replace single and double quotes

2006-08-29 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
 since I had something similar as a problem, let m etry to anser ang see
 did I get it correct :)

seems ok ...

 
 first, and most important: never store in DB row submitted string
 
 $act_extra = mysql_real_escape_string($_POST[editextra]);
 $act_extra_fr = mysql_real_escape_string($_POST[editextrafr])

the following should always be an integer (probably) ...

 $act_id = mysql_real_escape_string($_POST[editid]);

so why not do:

$act_id = intval($_POST[editid]);
if (!$act_id) die('go away script kiddie!');

 
 then:
 $sqledit = 
 update activities
 set act_extra='.$act_extra.',
 act_extra_fr = '.$act_extra_fr.'
 where act_id = '.$act_id.';

very minor point - but why not save your eyes a little:

$sqledit = UPDATE activities
SET act_extra='{$act_extra}',
act_extra_fr='{$act_extra_fr}'
WHERE act_id={$act_id};

 
 to check:
 echo $sqledit;
 
 it should work now.
 
 hope this helped.
 
 -afan
 
 
 
 This is the code is use to insert/update text into a database field:

 $sqledit=update activities set act_extra='$_POST[editextra]',
 act_extra_fr='$_POST[editextrafr]' where act_id=$_POST[editid];

 Now both $_POST[editextra] and $_POST[editextrafr] can contain single or
 double quotes.
 So the query almost always gives me an error.

 I know I have to replace  with quot, but I do not know how to replace
 the
 single quote so it is shown as a single quote on a webpage when I get it
 from the database

 I have been looking into str_replace and preg_replace. But what I really
 need is a solution that 'replaces' single quotes, double quotes en curly
 quotes so I tackle all possible problems and the same text as it was
 inputed
 in the textarea is shown on the webpage.

 Thx in advance

 --
 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] replace single and double quotes

2006-08-29 Thread Jochem Maas
Reinhart Viane wrote:
 This is the code is use to insert/update text into a database field:
 
 $sqledit=update activities set act_extra='$_POST[editextra]',
 act_extra_fr='$_POST[editextrafr]' where act_id=$_POST[editid];

this indicates 'bad' database design ... because adding a language involves
having to change the database schema. I personally think that there should be
no need to change the database schema and/or queries and/or code just because
the client wants an extra language.

it also indicates that you have a glaring SQL injection problem. what happens
when I craft a POST request that contains an 'editid' parameter with the 
following in it:

'1 OR 1'

or

'1; DELETE * FROM activities'

google 'SQL injection', do some reading and get into the habit of sanitizing
your user input.

 
 Now both $_POST[editextra] and $_POST[editextrafr] can contain single or
 double quotes.
 So the query almost always gives me an error.
 
 I know I have to replace  with quot, but I do not know how to replace the

WRONG - you only replace  with quot when you OUTPUTTING the string as part of 
a
webpage. the database should contain the actual

 single quote so it is shown as a single quote on a webpage when I get it
 from the database

mysql_real_escape_string()

search this archive; there is plenty of discussion about escaping data so that 
it
can be inserted into a database (mostly concerning MySQL).

 
 I have been looking into str_replace and preg_replace. But what I really
 need is a solution that 'replaces' single quotes, double quotes en curly
 quotes so I tackle all possible problems and the same text as it was inputed
 in the textarea is shown on the webpage.
 
 Thx in advance
 

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



RE: [PHP] replace single and double quotes

2006-08-29 Thread Peter Lauri
Assumning $act_id is integer:

$act_extra = mysql_real_escape_string($_POST[editextra]);
$act_extra_fr = mysql_real_escape_string($_POST[editextrafr])
$act_id = $_POST[editid];

$sql = sprint(UPDATE activities SET act_extra='%s', act_extra_fr='%s' WHERE
act_id=%d, $act_extra, $act_extra_fr, $act_id);

Notice the %d for the id part if $act_id should be integer.

/Peter


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 29, 2006 8:28 PM
To: [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Subject: Re: [PHP] replace single and double quotes

since I had something similar as a problem, let m etry to anser ang see
did I get it correct :)

first, and most important: never store in DB row submitted string

$act_extra = mysql_real_escape_string($_POST[editextra]);
$act_extra_fr = mysql_real_escape_string($_POST[editextrafr])
$act_id = mysql_real_escape_string($_POST[editid]);

then:
$sqledit = 
update activities
set act_extra='.$act_extra.',
act_extra_fr = '.$act_extra_fr.'
where act_id = '.$act_id.';

to check:
echo $sqledit;

it should work now.

hope this helped.

-afan



 This is the code is use to insert/update text into a database field:

 $sqledit=update activities set act_extra='$_POST[editextra]',
 act_extra_fr='$_POST[editextrafr]' where act_id=$_POST[editid];

 Now both $_POST[editextra] and $_POST[editextrafr] can contain single or
 double quotes.
 So the query almost always gives me an error.

 I know I have to replace  with quot, but I do not know how to replace
 the
 single quote so it is shown as a single quote on a webpage when I get it
 from the database

 I have been looking into str_replace and preg_replace. But what I really
 need is a solution that 'replaces' single quotes, double quotes en curly
 quotes so I tackle all possible problems and the same text as it was
 inputed
 in the textarea is shown on the webpage.

 Thx in advance

 --
 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] replace single and double quotes

2006-08-29 Thread Reinhart Viane
About the language remark:
I believe you try to say I need to find a way that the client can add 25
languages without me having to change the database layout or the coding?
Well I can assure you this will not be the fact. The client only needs these
two languages but maybe I should look into it anyway

About SQl injection:
I must say this is very interesting.
I always wondered what are does and donts when inserting data from a form
into a database and how to check someone did not enter any php code.
Besides the google lookup is there maybe an site or paper dedicated to this?

Thx again, didn't think this question was about to bring up what I was
looking for in the back of my head


-Oorspronkelijk bericht-
Van: Jochem Maas [mailto:[EMAIL PROTECTED] 
Verzonden: dinsdag 29 augustus 2006 15:37
Aan: [EMAIL PROTECTED]
CC: php-general@lists.php.net
Onderwerp: Re: [PHP] replace single and double quotes

Reinhart Viane wrote:
 This is the code is use to insert/update text into a database field:
 
 $sqledit=update activities set act_extra='$_POST[editextra]',
 act_extra_fr='$_POST[editextrafr]' where act_id=$_POST[editid];

this indicates 'bad' database design ... because adding a language involves
having to change the database schema. I personally think that there should
be
no need to change the database schema and/or queries and/or code just
because
the client wants an extra language.

it also indicates that you have a glaring SQL injection problem. what
happens
when I craft a POST request that contains an 'editid' parameter with the
following in it:

'1 OR 1'

or

'1; DELETE * FROM activities'

google 'SQL injection', do some reading and get into the habit of sanitizing
your user input.

 
 Now both $_POST[editextra] and $_POST[editextrafr] can contain single or
 double quotes.
 So the query almost always gives me an error.
 
 I know I have to replace  with quot, but I do not know how to replace
the

WRONG - you only replace  with quot when you OUTPUTTING the string as part
of a
webpage. the database should contain the actual

 single quote so it is shown as a single quote on a webpage when I get it
 from the database

mysql_real_escape_string()

search this archive; there is plenty of discussion about escaping data so
that it
can be inserted into a database (mostly concerning MySQL).

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



RE: [PHP] replace single and double quotes

2006-08-29 Thread Reinhart Viane
Ok 'ill give this a shot together with the guidelines from jochen.

Thx afan.

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Verzonden: dinsdag 29 augustus 2006 15:28
Aan: [EMAIL PROTECTED]
CC: php-general@lists.php.net
Onderwerp: Re: [PHP] replace single and double quotes

since I had something similar as a problem, let m etry to anser ang see
did I get it correct :)

first, and most important: never store in DB row submitted string

$act_extra = mysql_real_escape_string($_POST[editextra]);
$act_extra_fr = mysql_real_escape_string($_POST[editextrafr])
$act_id = mysql_real_escape_string($_POST[editid]);

then:
$sqledit = 
update activities
set act_extra='.$act_extra.',
act_extra_fr = '.$act_extra_fr.'
where act_id = '.$act_id.';

to check:
echo $sqledit;

it should work now.

hope this helped.

-afan



 This is the code is use to insert/update text into a database field:

 $sqledit=update activities set act_extra='$_POST[editextra]',
 act_extra_fr='$_POST[editextrafr]' where act_id=$_POST[editid];

 Now both $_POST[editextra] and $_POST[editextrafr] can contain single or
 double quotes.
 So the query almost always gives me an error.

 I know I have to replace  with quot, but I do not know how to replace
 the
 single quote so it is shown as a single quote on a webpage when I get it
 from the database

 I have been looking into str_replace and preg_replace. But what I really
 need is a solution that 'replaces' single quotes, double quotes en curly
 quotes so I tackle all possible problems and the same text as it was
 inputed
 in the textarea is shown on the webpage.

 Thx in advance

 --
 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] replace single and double quotes

2006-08-29 Thread Jochem Maas
Reinhart Viane wrote:
 About the language remark:
 I believe you try to say I need to find a way that the client can add 25
 languages without me having to change the database layout or the coding?
 Well I can assure you this will not be the fact. The client only needs these
 two languages but maybe I should look into it anyway

it's more a of a theoretical thing. but if the client wants french and flemish
(or dutch) now there is a distinct chance that they will want to add dutch,
english and/or german in the forseeable future... going by my experience of
building multilingual sites for [west] european companies (I have one
client that actually wanted flemish as well as dutch so that they could tailor 
texts
in the flemish pages specifically to [search] terms regularly used in belgium).

your db design may very well be sufficient for this particular case.

 
 About SQl injection:
 I must say this is very interesting.
 I always wondered what are does and donts when inserting data from a form
 into a database and how to check someone did not enter any php code.
 Besides the google lookup is there maybe an site or paper dedicated to this?

phpsec.org - recommended to read it back to front!

 
 Thx again, didn't think this question was about to bring up what I was
 looking for in the back of my head
 
 
 -Oorspronkelijk bericht-
 Van: Jochem Maas [mailto:[EMAIL PROTECTED] 
 Verzonden: dinsdag 29 augustus 2006 15:37
 Aan: [EMAIL PROTECTED]
 CC: php-general@lists.php.net
 Onderwerp: Re: [PHP] replace single and double quotes
 
 Reinhart Viane wrote:
 This is the code is use to insert/update text into a database field:

 $sqledit=update activities set act_extra='$_POST[editextra]',
 act_extra_fr='$_POST[editextrafr]' where act_id=$_POST[editid];
 
 this indicates 'bad' database design ... because adding a language involves
 having to change the database schema. I personally think that there should
 be
 no need to change the database schema and/or queries and/or code just
 because
 the client wants an extra language.
 
 it also indicates that you have a glaring SQL injection problem. what
 happens
 when I craft a POST request that contains an 'editid' parameter with the
 following in it:
 
   '1 OR 1'
 
 or
 
   '1; DELETE * FROM activities'
 
 google 'SQL injection', do some reading and get into the habit of sanitizing
 your user input.
 
 Now both $_POST[editextra] and $_POST[editextrafr] can contain single or
 double quotes.
 So the query almost always gives me an error.

 I know I have to replace  with quot, but I do not know how to replace
 the
 
 WRONG - you only replace  with quot when you OUTPUTTING the string as part
 of a
 webpage. the database should contain the actual
 
 single quote so it is shown as a single quote on a webpage when I get it
 from the database
 
 mysql_real_escape_string()
 
 search this archive; there is plenty of discussion about escaping data so
 that it
 can be inserted into a database (mostly concerning MySQL).
 
 

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



RE: [PHP] replace single and double quotes

2006-08-29 Thread Peter Lauri
It might be bad database design yes, however, it all depends on what he is
trying to do. I do it your way Jochem (normalizing the database), but in
some cases the budget to do that might not be big enough. If the client
gives you a task and an budget, normalizing the database might be a waste
of time.

I do recommend he should do some reading about SQL injection, phpsec.org is
probably good enough. But to get him going he could just learn that he
should always mysql_real_escape_string on strings, and if he expect integers
to come, use the sprintf and %d.

You can read my blog
http://www.lauri.se/article/4/security-hole-in-golfdatase about a big and
important golf organization in Sweden and how they screwed up about their
security.

Hrm, I might be wrong here :)

/Peter



-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 29, 2006 8:37 PM
To: [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Subject: Re: [PHP] replace single and double quotes

Reinhart Viane wrote:
 This is the code is use to insert/update text into a database field:
 
 $sqledit=update activities set act_extra='$_POST[editextra]',
 act_extra_fr='$_POST[editextrafr]' where act_id=$_POST[editid];

this indicates 'bad' database design ... because adding a language involves
having to change the database schema. I personally think that there should
be
no need to change the database schema and/or queries and/or code just
because
the client wants an extra language.

it also indicates that you have a glaring SQL injection problem. what
happens
when I craft a POST request that contains an 'editid' parameter with the
following in it:

'1 OR 1'

or

'1; DELETE * FROM activities'

google 'SQL injection', do some reading and get into the habit of sanitizing
your user input.

 
 Now both $_POST[editextra] and $_POST[editextrafr] can contain single or
 double quotes.
 So the query almost always gives me an error.
 
 I know I have to replace  with quot, but I do not know how to replace
the

WRONG - you only replace  with quot when you OUTPUTTING the string as part
of a
webpage. the database should contain the actual

 single quote so it is shown as a single quote on a webpage when I get it
 from the database

mysql_real_escape_string()

search this archive; there is plenty of discussion about escaping data so
that it
can be inserted into a database (mostly concerning MySQL).

 
 I have been looking into str_replace and preg_replace. But what I really
 need is a solution that 'replaces' single quotes, double quotes en curly
 quotes so I tackle all possible problems and the same text as it was
inputed
 in the textarea is shown on the webpage.
 
 Thx in advance
 

-- 
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] replace single and double quotes

2006-08-29 Thread tedd

At 5:04 PM +0200 8/29/06, Reinhart Viane wrote:

About the language remark:
I believe you try to say I need to find a way that the client can add 25
languages without me having to change the database layout or the coding?
Well I can assure you this will not be the fact. The client only needs these
two languages but maybe I should look into it anyway


Depends upon what's in the dB -- if it's language specific, then 
you'll have to change it. If it's not, then you won't.


For what it's worth, the language independent code that I've written 
in the past used constants for language specific labels. From there, 
I would program using English for my code, but those constants could 
be changed by a single setting allowing them to be their language 
counterparts. Food for thought.



About SQl injection:
I must say this is very interesting.
I always wondered what are does and donts when inserting data from a form
into a database and how to check someone did not enter any php code.
Besides the google lookup is there maybe an site or paper dedicated to this?


There are different types of injection. I recommend Essential PHP 
Security by Shifiett:


http://www.amazon.com/gp/product/059600656X/ref=nosim/102-4387829-1116967?camp=2025dev-t=D26XECQVNV6NDQlink%5Fcode=xm2n=283155

Well worth the money.

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] replace single and double quotes

2006-08-29 Thread Rafael Mora

Hi!

i want to send a file or output stream in a .php, but first compress it, I
tryed the example to compress files but how do i do to send as answer to the
http request??

Rafa


Re: [PHP] replace

2005-09-19 Thread tg-php
I hope this is what you were looking for:

$contents = Numbers 1, 2, 3, 4 and 5 will be replaced with A, B, C, D, and E;
$searcharr =  array(1, 2, 3, 4, 5);
$replacearr = array(A, B, C, D, E);
$newcontents = str_replace($searcharr, $replacearr, $contents);

echo $newcontents;

Numbers A, B, C, D and E will be replaced with A, B, C, D, and E

Good luck!

-TG

= = = Original message = = =

Hi all

if I have an array of chars to be replaced array(1,2,3,4,5);
and an arry of chars to replace with array(a,b,c,d,e)

what function do I need to replace all chars from one arry to the other that 
are found in the var $contents

Thanks

M 


___
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] replace striing éèêà

2005-06-06 Thread Jochem Maas

John Taylor-Johnston wrote:
Can someone show me how to get rid of international characters in 
$string? Is there a function already made?


the acute/grave accents on the chars are called 'diacritics'

You cannot use accented characters in a name reference : a 
name=montréal.

I guess this below is a start. Is there a better way?
John

http://ca.php.net/manual/en/function.str-replace.php
$string = àâéèç;
|$find = array(à, â, é, è, ç);
||$||replacewith|| = array(a, a, e, e, c);||
$onlyconsonants = str_replace($vowels, $replacewith, $string);



?php
// you could do something like:

function getUndiacritical($word)
{

$base_drop_char_match =   array('^', '$', '', '(', ')', '', '', '`', '\'', '', '|', ',', '@', '_', '?', '%', '-', 
'~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
$base_drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '',  '',   ' ', ' ', ' ', ' ', '',  ' ', ' ', '',  ' 
', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ',  ' ', ' ');


$xtr_drop_char_match   = array('à', 'â', 'ä', 'æ', 'è', 'ê', 'ì', 'î', 'ð', 'ò', 'ô', 'ö', 'ø', 'ú', 'ü', 'ß', 'á', 'ã', 
'å', 'ç', 'é', 'ë', 'í', 'ï', 'ñ', 'ó', 'õ', 'ù', 'û', 'ý', 'ÿ');
$xtr_drop_char_replace = array('a', 'a', 'a', 'a', 'e', 'e', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 's', 'a', 'a', 
'a', 'c', 'e', 'e', 'i', 'i', 'n', 'o', 'o', 'u', 'u', 'y', 'y');


$drop_char_match   = array_merge( $base_drop_char_match, $xtr_drop_char_match );
$drop_char_replace = array_merge( $base_drop_char_replace, 
$xtr_drop_char_replace );

return str_replace($drop_char_match, $drop_char_replace, $word);

}

// alternatively


function getUndiacritical2($word)
{

$base_drop_char_match =   array('^', '$', '', '(', ')', '', '', '`', '\'', '', '|', ',', '@', '_', '?', '%', '-', 
'~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
$base_drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '',  '',   ' ', ' ', ' ', ' ', '',  ' ', ' ', '',  ' 
', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ',  ' ', ' ');


$xtr_drop_char_match   = array('à', 'â', 'ä', 'æ', 'è', 'ê', 'ì', 'î', 'ð', 'ò', 'ô', 'ö', 'ø', 'ú', 'ü', 'ß', 'á', 'ã', 
'å', 'ç', 'é', 'ë', 'í', 'ï', 'ñ', 'ó', 'õ', 'ù', 'û', 'ý', 'ÿ');
$xtr_drop_char_replace = array('a', 'a', 'a', 'a', 'e', 'e', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 's', 'a', 'a', 
'a', 'c', 'e', 'e', 'i', 'i', 'n', 'o', 'o', 'u', 'u', 'y', 'y');


$drop_char_match   = join('',array_merge( $base_drop_char_match, 
$xtr_drop_char_match ));
$drop_char_replace = join('',array_merge( $base_drop_char_replace, 
$xtr_drop_char_replace ));

return strtr($drop_char_match, $drop_char_replace, $word);

}


?

I doubt either of these funcs is perfect but it hopefully gives you a clue in 
the right
redirection.

rgds,
Jochem



|



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



Re: [PHP] replace striing éèêà

2005-06-05 Thread Chris

Look into strtr()

http://www.php.net/strtr

It seems to be precisely what you want.

John Taylor-Johnston wrote:

Can someone show me how to get rid of international characters in 
$string? Is there a function already made?
You cannot use accented characters in a name reference : a 
name=montréal.

I guess this below is a start. Is there a better way?
John

http://ca.php.net/manual/en/function.str-replace.php
$string = àâéèç;
|$find = array(à, â, é, è, ç);
||$||replacewith|| = array(a, a, e, e, c);||
$onlyconsonants = str_replace($vowels, $replacewith, $string);

|



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



Re: [PHP] replace special characters

2005-02-24 Thread Jason Wong
On Thursday 24 February 2005 16:14, Frank Arensmeier wrote:

 1) replace .. with a string like file://server/folder
 2) replace all \ characters with /.

 The PHP code looks something like:

 $path_to_file = ..\1 PDF Filer\65051.PDF;

  $path_to_file = '..\1 PDF Filer\65051.PDF';

Don't use double-quoted strings unless you *need* to. Ditto for the rest 
of your code.

 The big problem is the character \ which, if I got it right, in
 UNICODE is used for things like expressing line breaks ('\n' or
 something like this).

\n is a newline character, however it has nothing to do with unicode, 
RTFM for details.

 The code above is resulting in the following 
 error massage: Parse error: parse error, expecting `')'' in
 /xxx/xxx/xxx/TMPz06yoces6o.php on line 2.

Switch to using a decent syntax highlighting editor and these types of 
errors will be immediately obvious.

-- 
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
--
New Year Resolution: Ignore top posted posts

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




Re: [PHP] replace

2005-01-28 Thread Richard Lynch
blackwater dev wrote:
 I have a section of my site that uses HTMLArea to allow the users to
 manage content.  For one certain section, they want all of their links
 to pop up in another window.  I know they can use HTMLArea and add
 this code themselves but they don't want to get to the code side of
 it.

 Currently, I just pull out the entire contents and echo them to the
 screen:

 echo $sql-getField('content');

 but now I need to replace each anchor tag from
 A href=http://www.something.com/;
 to
 A href=javascript:pop('http://www.something.com/')

 I can easily use str_replace() to replace a href=javascript:pop( 
 but how do I add the last )?

http://php.net/preg_replace
would probably be easiest.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] replace

2005-01-28 Thread blackwater dev
thanks...I will look that up.  Not very good with regular expressions though.


On Fri, 28 Jan 2005 08:11:59 -0800 (PST), Richard Lynch [EMAIL PROTECTED] 
wrote:
 blackwater dev wrote:
  I have a section of my site that uses HTMLArea to allow the users to
  manage content.  For one certain section, they want all of their links
  to pop up in another window.  I know they can use HTMLArea and add
  this code themselves but they don't want to get to the code side of
  it.
 
  Currently, I just pull out the entire contents and echo them to the
  screen:
 
  echo $sql-getField('content');
 
  but now I need to replace each anchor tag from
  A href=http://www.something.com/;
  to
  A href=javascript:pop('http://www.something.com/')
 
  I can easily use str_replace() to replace a href=javascript:pop( 
  but how do I add the last )?
 
 http://php.net/preg_replace
 would probably be easiest.
 
 --
 Like Music?
 http://l-i-e.com/artists.htm
 


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



Re: [PHP] replace

2005-01-28 Thread Jochem Maas
blackwater dev wrote:
thanks...I will look that up.  Not very good with regular expressions though.
this is your chance to get a bit better. have a go,
if you get stuck post your code :-)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Replace credit card numbers with X ???

2005-01-25 Thread Jay Blanchard
[snip]
I need to replace all the numbers of a credit card except for the last
4 with an 'X' ... can't seem to locate the string function for this...
can someone point me in the right direction here to what php item i
should be using.
[/snip]

ROFLMMFAO! It's all been discussed before Joe! 

http://www.php.net/ereg_replace

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



Re: [PHP] Replace credit card numbers with X ???

2005-01-25 Thread Afan Pasalic
this is my way.
   $cc_stars = '';
   $cc_no_lenght = strlen($cc_number);
   $cc_info_first4 = substr($cc_number, 0, 4);
   $cc_info_last4 = substr($cc_number, (strlen($cc_number) - 4), 4);
   for($i=0; $i($cc_no_lenght-8); $i++) $cc_stars .= '*';
   $cc_number = $cc_info_first4 .$cc_stars. $cc_info_last4;
-afan
Joe Harman wrote:
Hello,
I need to replace all the numbers of a credit card except for the last
4 with an 'X' ... can't seem to locate the string function for this...
can someone point me in the right direction here to what php item i
should be using.
Thanks!
Joe
 

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


[PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numbers with X ???)]

2005-01-25 Thread Afan Pasalic
Hey!
I just got this emai lfrom RIPN mail processor at Moscow ?!?!?!?!?
What's going on?
-afan
 Original Message 
Subject: 	DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card 
numbers with X ???)
Date: 	Tue, 25 Jan 2005 19:13:27 +0300
From: 	RIPN NCC [EMAIL PROTECTED]
To: 	php-general@lists.php.net,[EMAIL PROTECTED]


Dear Madam/Sir,
Here are results of  processing your  request:
From:Afan Pasalic [EMAIL PROTECTED]
Subject: Re: [PHP] Replace credit card numbers with X ???
Date:Tue, 25 Jan 2005 10:06:21 -0600
Msg-Id:  [EMAIL PROTECTED]

this is my way.
unrecognized statment - line ignored.
$cc_stars = '';
unrecognized statment - line ignored.
$cc_no_lenght = strlen($cc_number);
unrecognized statment - line ignored.
$cc_info_first4 = substr($cc_number, 0, 4);
unrecognized statment - line ignored.
$cc_info_last4 = substr($cc_number, (strlen($cc_number) - 4), 4);
unrecognized statment - line ignored.
for($i=0; $i($cc_no_lenght-8); $i++) $cc_stars .= '*';
unrecognized statment - line ignored.
$cc_number = $cc_info_first4 .$cc_stars. $cc_info_last4;
unrecognized statment - line ignored.

-afan
unrecognized statment - line ignored.
Joe Harman wrote:
unrecognized statment - line ignored.
Hello,
unrecognized statment - line ignored.

unrecognized statment - line ignored.
I need to replace all the numbers of a credit card except for the last
unrecognized statment - line ignored.
4 with an 'X' ... can't seem to locate the string function for this...
unrecognized statment - line ignored.
can someone point me in the right direction here to what php item i
unrecognized statment - line ignored.
should be using.
unrecognized statment - line ignored.
Too many warnings (max. 2) - FATAL ERROR!

Thanks!
Joe

  


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

Your current request counter: 1.
You may send us 119 in this hour.
Thank you,
RIPN mail processor.
Tue Jan 25 19:13:27 MSK/MSD 2005
Moscow, Russia.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Replace credit card numbers with X ???

2005-01-25 Thread Jochem Maas
Joe Harman wrote:
Hello,
I need to replace all the numbers of a credit card except for the last
4 with an 'X' ... can't seem to locate the string function for this...
can someone point me in the right direction here to what php item i
should be using.
that'll be:
string php_replace_all_but_last_four_chars_of_creditcard_number(string input[, 
string pad_string])
actually that func doesn't exist - what you need to do (well its one way to do 
it)
is use a combination of substr() and str_pad() e.g:
echo str_pad(substr($cc, -4), 20, 'X', STR_PAD_LEFT);
where $cc is the previously checked/verified/sanitized creditcard no.
and 20 is the length of a creditcard no. - forgive me if I'm wrong about the CC
number length, I don't have a creditcard.
Thanks!
Joe
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Replace credit card numbers with X ???

2005-01-25 Thread tg-php
In addition to what was mentioned already, using ereg_replace, if you're 
pulling the CC# string out of a database of off of some POST data or something, 
just use a substr() function to pull the last 4 digits and prepend a bunch of 
X's.

$ccnum = 342342522342342;  # fake CC #, prob not even correct # of digits :)
$maskedccnum = XXX . substr($ccnum,strlen($ccnum)-5,4);


If you're trying to do it in a form, realtime as the user enters it, you'd have 
to use some funky javascript or do something with a password form type or 
something.  But sounds like you want it like when you display an invoice 
afterwards or display a Would you like to use this CC that's already on file? 
type thing without exposing the whole CC#.

-TG

= = = Original message = = =

Hello,

I need to replace all the numbers of a credit card except for the last
4 with an 'X' ... can't seem to locate the string function for this...
can someone point me in the right direction here to what php item i
should be using.

Thanks!
Joe


___
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] Replace credit card numbers with X ???

2005-01-25 Thread Jochem Maas
Jay Blanchard wrote:
[snip]
I need to replace all the numbers of a credit card except for the last
4 with an 'X' ... can't seem to locate the string function for this...
can someone point me in the right direction here to what php item i
should be using.
[/snip]
ROFLMMFAO! It's all been discussed before Joe! 

http://www.php.net/ereg_replace
not-too-serious
wtf :-), I can't find any particular mention of his problem on that page
 (and I know how to use the CTRL+f keycombo in firefox, thanks for asking :-).
regardless of whether ereg_replace() would satisfy his needs pointing him at
that page without explaination is a bit stupid - the guy obviously doesn't
have even half a clue with regards to string manipulation - therefore I think
its safe to assume that regexps are a bit out of his league.
but then again if he is working with (_other_peoples_) creditcard numbers
he should probably:
a, know this shit.
or
b, be capable of finding the answer in the manual.
n'est pas?
anyway I had fun remembering exactly what ROFLMMFAO meant :-), and the tinge
of RTFM at Joe was probably justified - and even if it wasn't I condone it :-)
is it fair game to throw someone an RTFM after you have helped them?
/not-too-serious
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numbers with X ???)]

2005-01-25 Thread Richard Davey
Hello Afan,

Tuesday, January 25, 2005, 4:12:43 PM, you wrote:

AP Hey!
AP I just got this emai lfrom RIPN mail processor at Moscow ?!?!?!?!?

Join the club.. everyone who posts gets one. Annoying, no?

Best regards,

Richard Davey
-- 
 http://www.launchcode.co.uk - PHP Development Services
 I am not young enough to know everything. - Oscar Wilde

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



RE: [PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numberswith X ???)]

2005-01-25 Thread Jay Blanchard
[snip]
I just got this emai lfrom RIPN mail processor at Moscow ?!?!?!?!?

What's going on?
[/snip]

I have been getting it with every send too...off to /dev/null

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



RE: [PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numbers with X ???)]

2005-01-25 Thread Mike Johnson
From: Richard Davey [mailto:[EMAIL PROTECTED] 

 Hello Afan,
 
 Tuesday, January 25, 2005, 4:12:43 PM, you wrote:
 
 AP Hey!
 AP I just got this emai lfrom RIPN mail processor at Moscow ?!?!?!?!?
 
 Join the club.. everyone who posts gets one. Annoying, no?
 
 Best regards,
 
 Richard Davey

My personal favorite is when someone requests a read receipt on
listmail. I wonder what their inbox looks like when 500 people send one
back all in the space of five minutes.


-- 
Mike Johnson Smarter Living, Inc.
Web Developerwww.smartertravel.com
[EMAIL PROTECTED]   (617) 886-5539

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



Re: [PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numbers with X ???)]

2005-01-25 Thread Afan Pasalic
Not at all... Actually, I enjoy  :-D
I just wonder what's going on and is it problem on my side or... Now I 
breath easier...

;-)
-afan

Richard Davey wrote:
Hello Afan,
Tuesday, January 25, 2005, 4:12:43 PM, you wrote:
AP Hey!
AP I just got this emai lfrom RIPN mail processor at Moscow ?!?!?!?!?
Join the club.. everyone who posts gets one. Annoying, no?
Best regards,
Richard Davey
 

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


[PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numberswith X ???)]

2005-01-25 Thread Chris Ramsay
snip
Join the club.. everyone who posts gets one. Annoying, no?
/snip

Maybe that's another thing to add to the [NEWBIE GUIDE] - I would have found
it useful! ;)

Chris Ramsay
-
Web Developer - The Danwood Group Ltd.
T: +44 (0) 1522 834482
F: +44 (0) 1522 884488
e: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
w: http://www.danwood.co.uk
-

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



Re: [PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numberswith X ???)]

2005-01-25 Thread Richard Davey
Hello Chris,

Tuesday, January 25, 2005, 5:07:37 PM, you wrote:

CR Maybe that's another thing to add to the [NEWBIE GUIDE] - I would have found
CR it useful! ;)

Ahh... so you're the Russian mail server? :)

I guess we could add don't be a twat with your auto-responders to
the newbie faq, but really no-one ever pays any attention!

Best regards,

Richard Davey
-- 
 http://www.launchcode.co.uk - PHP Development Services
 I am not young enough to know everything. - Oscar Wilde

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



RE: [PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numberswith X ???)]

2005-01-25 Thread Chris Ramsay
snip

Hey!
I just got this emai lfrom RIPN mail processor at Moscow ?!?!?!?!?

/snip

I have received this also with both my postings today...and probably will
again...

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



Re: [PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numbers with X ???)]

2005-01-25 Thread John Nichel
Mike Johnson wrote:
From: Richard Davey [mailto:[EMAIL PROTECTED] 


Hello Afan,
Tuesday, January 25, 2005, 4:12:43 PM, you wrote:
AP Hey!
AP I just got this emai lfrom RIPN mail processor at Moscow ?!?!?!?!?
Join the club.. everyone who posts gets one. Annoying, no?
Best regards,
Richard Davey

My personal favorite is when someone requests a read receipt on
listmail. I wonder what their inbox looks like when 500 people send one
back all in the space of five minutes.
I usually just delete those without a second glance, but you may be on 
to something...if we all send the read receipt, then maybe the user will 
get tired of all the receipts and turn it off. ;)

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] [Fwd: DNS.050125191312.29782 (Re: Re: [PHP] Replace credit card numberswith X ???)]

2005-01-25 Thread Jordi Canals
On Tue, 25 Jan 2005 16:29:38 -, Chris Ramsay
[EMAIL PROTECTED] wrote:
 snip
 
 Hey!
 I just got this emai lfrom RIPN mail processor at Moscow ?!?!?!?!?
 
 /snip
 
 I have received this also with both my postings today...and probably will
 again...
 

I've just sent ONE message to the list today and I've got 8 times this
message ...

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



Re: [PHP] Replace or regex?

2004-09-30 Thread Gareth Williams
Well, if you can do it without a regex, then it's always best, because 
the regex engine slows things down.

On 30 Sep 2004, at 10:39, mario wrote:
Hi all
I have a string: ##CODE## and I want to replace that with a
href=somewhere.php?id=CODECODE/a
can u 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] Replace or regex?

2004-09-30 Thread Graham Cossey
If you can change the ##text## to say /#text#/ it would be easier as you
could then do something like:

$id = substr($orig_text,strpos($orig_text, '/#')+2,strpos($orig_text,
'#/')-1);
$new_text = str_replace( '/#', 'href=somewhere.php?id='.$id.'',
$orig_text);
$new_text = str_replace( '#/', '/a', $new_text);

see:
http://www.php.net/manual/en/ref.strings.php

HTH

Graham

-Original Message-
From: Gareth Williams [mailto:[EMAIL PROTECTED]
Sent: 30 September 2004 09:38
To: mario
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Replace or regex?



Well, if you can do it without a regex, then it's always best, because
the regex engine slows things down.

On 30 Sep 2004, at 10:39, mario wrote:

 Hi all

 I have a string: ##CODE## and I want to replace that with a
 href=somewhere.php?id=CODECODE/a

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

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



Re: [PHP] Replace or regex?

2004-09-30 Thread Brian
$var=##testcode##this is a ##code1## test of the ##code2## code
replacement system ##code3##;

$varParsed=strParse($var);
echo $varbr;
echo $varParsed;

function strParse($origString)
  {
  while ( $offsetstrlen($origString) 
!(($foundBeg=strpos($origString, ##, $offset))===FALSE))
{
if (($foundEnd=strpos($origString, ##, $foundBeg+2))FALSE)
  {
  $tmpString=substr($origString, $lastEnd, $foundBeg-$lastEnd);
  $tmpCode=substr($origString, $foundBeg+2, $foundEnd-($foundBeg+2));
  $finalString=$finalString . $tmpString . a
href='somewhere.php?id=$tmpCode'$tmpCode/a;
  $offset=$foundEnd+2;
  $lastEnd=$foundEnd+2;
  } else {
  echo Parse Errorbr;
  break;
  }
}
  return $finalString;
  }



On Thu, 30 Sep 2004 11:39:10 +0300, mario [EMAIL PROTECTED] wrote:
 Hi all
 
 I have a string: ##CODE## and I want to replace that with a
 href=somewhere.php?id=CODECODE/a
 
 can u 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] Replace or regex?

2004-09-30 Thread Dan Joseph
Hi,

  I have a string: ##CODE## and I want to replace that with a
  href=somewhere.php?id=CODECODE/a

I handle %code% tags in some templates I use...  here's the code I have..

function show ($template, $tag) {
$file = fopen ($template, r) or
die($error_string());

while (!feof($file)) {
$line_in   = fgets($file, 1024);
$line_out .= $line_in;
}

if ($tag != 0) {
foreach ($tag as $name = $value) {
$line_out = str_replace (%$name%,
$value, $line_out);
}
}

return $line_out;

fclose ($file);
}

Hope that helps..

-Dan Joseph

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



Re: [PHP] replace accents

2004-09-14 Thread Greg Donald
On Tue, 14 Sep 2004 17:51:00 +0200, Diana Castillo [EMAIL PROTECTED] wrote:
 Anyone know of any function to replace letters with accents with just the
 regular letter, for instance replace á with a,
 ç with c, ñ with n ?

str_replace(), eregi_replace()


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

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



Re: [PHP] replace accents

2004-09-14 Thread Marek Kilimajer
Diana Castillo wrote:
Anyone know of any function to replace letters with accents with just the 
regular letter, for instance replace á with a,
ç with c, ñ with n ?


$string = str_replace(array('á', 'ç', 'ñ'), array('a', 'c', 'n'), $string);
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] replace accents

2004-09-14 Thread Rick Fletcher
Diana Castillo wrote:
Anyone know of any function to replace letters with accents with just the 
regular letter, for instance replace  with a,
 with c,  with n ?
found this on the strtr() manual page (http://php.net/strtr):
?php
function removeaccents($string){
  return strtr(
strtr( $string,
  '',
  'SZszYAACNOOYaacnooyy' ),
   array(
 '' = 'TH', '' = 'th', '' = 'DH', '' = 'dh',
 '' = 'ss', '' = 'OE', '' = 'oe', '' = 'AE',
 '' = 'ae', '' = 'u' )
);
}
?
--rick
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] replace accents

2004-09-14 Thread -{ Rene Brehmer }-
At 17:51 14-09-2004, Diana Castillo wrote:
Anyone know of any function to replace letters with accents with just the
regular letter, for instance replace á with a,
ç with c, ñ with n ?
How about this ??? This is the one I made for this purpose
function stripAccents($string) {
  $returnString = strtr($string,
  'àáâãäçèéêëìíîïñòóôõöšùúûüýÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕ֊ÙÚÛÜÝ', 
'acnosyACNOSY');
  $returnString = str_replace('æ','ae',str_replace('Æ','AE',$returnString));
  $returnString = str_replace('ø','o',str_replace('Ø','O',$returnString));
  $returnString = str_replace('å','a',str_replace('Å','å',$returnString));
  $returnString = str_replace('ß','ss',$returnString);
  $returnString = str_replace('#039;','',str_replace(','',$returnString));
  $returnString = str_replace('quot;','',str_replace('','',$returnString));
  return $returnString;
}

obviously there's room for improvement, but it's from a QAD script (not 
production)

--
Rene Brehmer
aka Metalbunny
If your life was a dream, would you wake up from a nightmare, dripping of 
sweat, hoping it was over? Or would you wake up happy and pleased, ready to 
take on the day with a smile?

http://metalbunny.net/
References, tools, and other useful stuff...
Check out the new Metalbunny forums at http://forums.metalbunny.net/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Replace a button by an image

2004-07-30 Thread Jay Blanchard
[snip]
Is it possible to replace a button by an image with
PHP?
[/snip]

Yes, anything is possible. http://phpbutton.sourceforge.net/

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



Re: [PHP] Replace a button by an image

2004-07-30 Thread John Nichel
Jay Blanchard wrote:
Yes, anything is possible.
Can I be the next Queen of England?
--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Replace a button by an image

2004-07-30 Thread PHP Gen



 Jay Blanchard wrote:
  Yes, anything is possible.
 
 Can I be the next Queen of England?
 
 -- 
 John C. Nichel

Anythings possible...and with all your choices you
want to be an old fart??

:-)



=
--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)



__
Do you Yahoo!?
Y! Messenger - Communicate in real time. Download now. 
http://messenger.yahoo.com

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



Re: [PHP] replace value of array by key of array in string variable with pre g_replace()

2004-07-26 Thread Jason Wong
On Monday 26 July 2004 10:09, Turbo wrote:

 I have array variable and string variable.
 I want to replace value of array by key of array  in string variable
 with preg_replace().

 Example :
 $message=array(
 'name'='My Computer',
 'version'='1.0'
 );
 $strValue=I am $name,build version $version\n;

 How's to replace?

I'm not sure what you're trying to do. Could you elaborate? In particular 
where does preg_replace() fit in?

It seems you want $strValue to be I am My Computer,build version 1.0\n. If 
so:

1) you have completely misunderstood what preg_replace() is for
2) Use:
  $strValue=I am {$message['name']},build version {$message['version']}\n;
3) see manual  Types  Strings  'Complex syntax'

-- 
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 woman without a man is like a fish without a bicycle.
Therefore, a man without a woman is like a bicycle without a fish.
*/

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



Re: [PHP] Replace space from form field using preg_replace

2004-03-17 Thread Adam Voigt
http://www.php.net/str-replace

On Wed, 2004-03-17 at 15:48, Vernon wrote:
 I want to be able to replace a space that comes from a form field (such as
 in 123 My Street) with a + sign.
 
 Can anyone help me with this?
 
 Thanks
-- 

Adam Voigt
[EMAIL PROTECTED]

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



Re: [PHP] Replace space from form field using preg_replace

2004-03-17 Thread Red Wingate
str_replace( ,+,$var);

-- red

Vernon wrote:

I want to be able to replace a space that comes from a form field (such as
in 123 My Street) with a + sign.
Can anyone help me with this?

Thanks

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


Re: [PHP] Replace of ' in a query

2004-02-17 Thread Chris Shiflett
--- carlos castillo [EMAIL PROTECTED] wrote:
 Hi , i have the following problem, i have a form where a user can input
 any text, on that text may be a char is ' char(39) when i try to execute
 the sql query, i have an error for that ', i need to replace it for the
 html tag, for example  is quot; or by chr(39) i dont know, and then
 execute the sql query.

Yikes!

Never use user input directly in your SQL statements. This is very
dangerous.

There are functions to help you escape your data. For example, if you are
using MySQL, you can use this function:

http://www.php.net/mysql_escape_string

However, you should also validate your data before doing anything else.
Make sure it is exactly what type of data you are expecting, then escape
the string just prior to constructing your SQL statement.

Hope that helps.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
 Coming mid-2004
HTTP Developer's Handbook - Sams
 http://httphandbook.org/
PHP Community Site
 http://phpcommunity.org/

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



Re: [PHP] Replace of ' in a query

2004-02-17 Thread Brent Baisley
Look at the addslashes command. You should always escape the values you 
are accepting from user input. If you read almost any article on web 
site security, it will mention something called SQL injection among 
other things. This is a way to compromise your data.
For instance, what if a user entered:
1 OR A=A

Now what if you used that user input to filter a query. You may end up 
with:
SELECT * FROM db WHERE field=1 OR A=A

Which would return every record in the database.

On Feb 17, 2004, at 2:44 PM, carlos castillo wrote:

Hi , i have the following problem, i have a form where a user can input
any text, on that text may be a char is ' char(39) when i try to 
execute
the sql query, i have an error for that ', i need to replace it for the
html tag, for example  is quot; or by chr(39) i dont know, and then
execute the sql query.

i really appreciate your help, thanks.

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


[PHP] RE: [PHP-WIN] Re: [PHP] Replace of ' in a query

2004-02-17 Thread Svensson, B.A.T. (HKG)
Never trust the web...

Esacping is bad practis. Doing it, is to ask for trouble when you
try to port the code to another system that a) escapes in another
way, or b) does not escape at all, the transparent way to handle
quote are to quote them. This has been working for the last 40 to
50 years or so, and still works fine. Why not stay with a winner?

-Original Message-
From: Brent Baisley
To: carlos castillo
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: 2004-02-17 21:02
Subject: [PHP-WIN] Re: [PHP] Replace of ' in a query

Look at the addslashes command. You should always escape the values you 
are accepting from user input. If you read almost any article on web 
site security, it will mention something called SQL injection among 
other things. This is a way to compromise your data.
For instance, what if a user entered:
1 OR A=A

Now what if you used that user input to filter a query. You may end up 
with:
SELECT * FROM db WHERE field=1 OR A=A

Which would return every record in the database.

On Feb 17, 2004, at 2:44 PM, carlos castillo wrote:

 Hi , i have the following problem, i have a form where a user can
input
 any text, on that text may be a char is ' char(39) when i try to 
 execute
 the sql query, i have an error for that ', i need to replace it for
the
 html tag, for example  is quot; or by chr(39) i dont know, and then
 execute the sql query.

 i really appreciate your help, thanks.

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

-- 
PHP Windows 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] replace ' with

2004-02-11 Thread Stuart
Diana Castillo wrote:
How do I replace all single quotes with double quotes in a string for
echoing it with the double quotes?
$text = str_replace(', '', $text);

http://php.net/str_replace and please at least RTFM before posting here 
in future.

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


RE: [PHP] replace ' with

2004-02-11 Thread Angelo Zanetti

str_replace(''',', $StringToReplace);

should work

-Original Message-
From: Diana Castillo [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 11, 2004 4:33 PM
To: [EMAIL PROTECTED]
Subject: [PHP] replace ' with 


How do I replace all single quotes with double quotes in a string for
echoing it with the double quotes?

--
Diana Castillo
Global Reservas, S.L.
C/Granvia 22 dcdo 4-dcha
28013 Madrid-Spain
Tel : 00-34-913604039 ext 214
Fax : 00-34-915228673
email: [EMAIL PROTECTED]
Web : http://www.hotelkey.com
  http://www.destinia.com

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


Disclaimer 
This e-mail transmission contains confidential information,
which is the property of the sender.
The information in this e-mail or attachments thereto is 
intended for the attention and use only of the addressee. 
Should you have received this e-mail in error, please delete 
and destroy it and any attachments thereto immediately. 
Under no circumstances will the Cape Technikon or the sender 
of this e-mail be liable to any party for any direct, indirect, 
special or other consequential damages for any use of this e-mail.
For the detailed e-mail disclaimer please refer to 
http://www.ctech.ac.za/polic or call +27 (0)21 460 3911

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



Re: [PHP] replace ' with

2004-02-11 Thread John Nichel
Diana Castillo wrote:

How do I replace all single quotes with double quotes in a string for
echoing it with the double quotes?
By looking here...

http://us4.php.net/str_replace

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] replace %rand[x]-[y]% macro in string with random string

2003-12-04 Thread daniel hahler
on Tue, 2 Dec 2003 23:46:33 +0100 I already wrote, regarding replacing
macro %rand[x]-[y] with random of random length ([x]-[y]).

Before, I had my own (slow!) procedure to find next occurence of the
macro and generated a new string, which was returned.

This took about 15 seconds for 10.000 addresses, where the macro could
appear. As this was too slow, I rewrote it to use preg_replace (what a
cool thing, to use a function as replacement) and this takes it down
to about 2,5 seconds!!

Very great - just want to lez you know that.. ;)

So this is it:

 // replaces %rand[x]-[y]% with random text with length between [x] and [y]
 function parserandstr($toparse){
  function genrandstr($minlen, $maxlen){
   echo $minlen, $maxlen, 'br';
   $ch = array(
'punct' = array('.', '.', '.', '..', '!', '!!', '?!'),
'sep' = array(', ', ' - '),
'vocal' = array('a', 'e', 'i', 'o', 'u'),
'cons_low' = array('x', 'y', 'z'),
'cons_norm' = array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 
'q', 'r', 's', 't', 'v', 'w')
   );
   $ch['newlineafter'] = array_merge(' ', $ch['punct'], $ch['sep']);

   $rlen = rand($minlen, $maxlen);

   // generate random string
   $randstr = ''; $inword = 0; $insentence = 0; $lastchar = ''; $lastwasvocal = false; 
$lastnewline = 0;
   $rbreak = rand(0, 100);
   for ($j = 0; $j  $rlen; $j++){
if ($inword  3  rand(0, 5) == 1) {  // punctuation chars
 if (rand(0,5)  0) $char = ' ';
 else {
  $char = $ch['punct'][rand(0, count($ch['punct'])-1)] . ' ';
  $j += strlen($char)-1;
  $insentence = 0;
 }
 $inword = 0;
}
else {
 if (!$lastwasvocal  rand(0, 10)  6) {  // vocals
  $char = $ch['vocal'][rand(0, count($ch['vocal'])-1)];
  $lastwasvocal = true;
 } else {
  do {
   if (rand(0, 30)  0)  // normal priority consonants
$char = $ch['cons_norm'][rand(0, count($ch['cons_norm'])-1)];
   else $char = $ch['cons_low'][rand(0, count($ch['cons_low'])-1)];
  } while ($char == $lastchar);
  $lastwasvocal = false;
 }
 $inword++;
 $insentence++;
}

if ($insentence == 1 || ($inword == 1  rand(0, 30)  10)) $randstr .= 
strtoupper($char);
else $randstr .= $char;
$lastchar = $char;
if ($lastnewline  $rbreak  rand(0, 30)  10  in_array($char, 
$ch['newlineafter'])){
 $randstr .= \n;
 $lastnewline = 0;
 $rbreak = rand(0, 100);
} else $lastnewline++;
   }
   return $randstr;
  }

  $pattern = array('/%rand(\d+)-(\d+)%/e', '/%rand%/e');
  $replace = array('genrandstr($1, $2)', 'genrandstr(5, 40)');
  return preg_replace($pattern, $replace, $toparse);
 }


-- 
shinE!
http://www.thequod.de ICQ#152282665
PGP 8.0 key: http://thequod.de/danielhahler.asc

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



Re: [PHP] replace %rand[x]-[y]% macro in string with random string

2003-12-02 Thread Richard Davey
Hello Daniel,

Tuesday, December 2, 2003, 10:46:33 PM, you wrote:

dh For generation of a random string with length 1.000.000 it takes about
dh 13 seconds on my xp 1600+.. that's quite a lot, imho, so suggestions
dh are very welcome..

Just so we're clear on this - you're creating a string (an email
address) of a million characters? I don't know my mail RFC's that well, but
I'm sure this is well beyond what it considers standard.

Does the string HAVE to make sense? I mean does a spambot really
care less, or can even detect, what the email address contains? Surely
just creating a truly random string would suffice (and indeed remove
the need for the rather elaborate function you posted). I fully accept
I might be missing the whole point here :)

-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

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



Re: [PHP] replace %rand[x]-[y]% macro in string with random string

2003-12-02 Thread Robert Cummings
On Tue, 2003-12-02 at 18:33, Richard Davey wrote:
 Hello Daniel,
 
 Tuesday, December 2, 2003, 10:46:33 PM, you wrote:
 
 dh For generation of a random string with length 1.000.000 it takes about
 dh 13 seconds on my xp 1600+.. that's quite a lot, imho, so suggestions
 dh are very welcome..
 

I missed the original post, and I'm too lazy to go looking, but the
following code runs in approx. 2.75 seconds on my Athlon 2400 running
linux:

$chars = '0123456789'
.'abcdefghijklmnopqrstuvwxyz'
.'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

$charArray = array();
 
for( $i = 0; $i  100; $i++ )
{
$charArray[] = $chars[rand( 0, 61 )];
}

It's runs much faster than using a .= style of string creation.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] replace %rand[x]-[y]% macro in string with random string

2003-12-02 Thread daniel hahler
on Tue, 2 Dec 2003 23:33:47 + Richard Davey wrote:

RD Just so we're clear on this - you're creating a string (an email
RD address) of a million characters? I don't know my mail RFC's that well, but
RD I'm sure this is well beyond what it considers standard.

We're not clear.. ;)
the function I've posted is designed for templates, that handle the
output my script generates.. it's useful to have non-email text
portions in between or a short random string for the mailto-links
description..

RD Does the string HAVE to make sense?

I found it better to follow some rules..
At first that were spaces in between and it got bigger.. if I'd write
a spambot I would check if the page I'm lurking on is a oneliner or
does only contain non-email words with  20 characters, and so on..


-- 
shinE!
http://www.thequod.de ICQ#152282665
PGP 8.0 key: http://thequod.de/danielhahler.asc

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



Re: [PHP] replace %rand[x]-[y]% macro in string with random string

2003-12-02 Thread daniel hahler
on 02 Dec 2003 18:56:28 -0500 Robert Cummings wrote:

RC I missed the original post, and I'm too lazy to go looking, but the
RC following code runs in approx. 2.75 seconds on my Athlon 2400 running
RC linux:

it is 4.3 seconds on xp 1600+..

RC $chars = '0123456789'
RC .'abcdefghijklmnopqrstuvwxyz'
RC .'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

RC $charArray = array();
 
RC for( $i = 0; $i  100; $i++ )
RC {
RC $charArray[] = $chars[rand( 0, 61 )];
RC }

RC It's runs much faster than using a .= style of string creation.

..and replacing $charArray[] = with $s .= crawls this down to 3.5
seconds - so this is faster here..

winxp, php 4.3.4, Apache 1.xx


-- 
shinE!
http://www.thequod.de ICQ#152282665
PGP 8.0 key: http://thequod.de/danielhahler.asc

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



Re: [PHP] replace a chunk peace of string

2003-12-01 Thread Curt Zirzow
* Thus wrote ada ([EMAIL PROTECTED]):
 select hex(a
 )
 -
 610D0A
 always 0D0A at the ends :(
 
 I' m on windows, and i didn't manage to destroy this peace of string :(
 trim() doesn't work ...

What do you mean trim() doesn't work? 


Curt
-- 
If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf, BDFL of PHP

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



Re: [PHP] replace a chunk peace of string

2003-12-01 Thread ada
 What do you mean trim() doesn't work?

trim is a basic function that remove spaces on the left and the right at the
string :
 abc-abc

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



Re: [PHP] replace a chunk peace of string

2003-12-01 Thread Curt Zirzow
* Thus wrote ada ([EMAIL PROTECTED]):
  What do you mean trim() doesn't work?
 
 trim is a basic function that remove spaces on the left and the right at the
 string :
  abc-abc

trim() removes more than spaces, please read:
  http://php.net/trim


What I meant in my original post was how are you using trim() that
doesn't make it work?  trim() *will* fix your problem.


Curt
-- 
If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf, BDFL of PHP

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



RE: [PHP] replace special chars

2003-11-05 Thread Jay Blanchard
[snip]
Are there any good function to replace special characters, for example 
double qoutes, with something that are more html-safe?
[/snip]

http://www.php.net/str_replace

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



Re: [PHP] replace special chars

2003-11-05 Thread Pavel Jartsev
Victor Spng Arthursson wrote:
Are there any good function to replace special characters, for example 
double qoutes, with something that are more html-safe?

For example:

option
label=Dekora Marilet Amerikano (9859)
value=98590
/option
The above is generated with PHP and fetched from a database 
(postgresql). I'ld like to have the double qoutes replaced with 
something else ;) There could be other strange characters as well that 
needs to be replaced, so some sort of universal function would be really 
nice to get tips on ;)

Sincerely

Victor

Try htmlspecialchars() and/or htmlentities().

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


Re: [PHP] replace special chars

2003-11-05 Thread Victor Spång Arthursson

2003-11-05 kl. 16.07 skrev Pavel Jartsev:
Try htmlspecialchars() and/or htmlentities().
htmlentities() did it best!

Thanks,

/.v

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


Re: [PHP] replace special chars

2003-11-05 Thread John W. Holmes
Victor Spng Arthursson wrote:
Are there any good function to replace special characters, for example 
double qoutes, with something that are more html-safe?
If only the PHP gods would bless us with a function such as 
htmlspecialchars() or maybe even htmlentities()... what a great world it 
would be... ;)

Take a look at the manual pages and they convert different character 
sets and handle quotes differently based upon the second parameter.

http://us2.php.net/htmlentities
http://us2.php.net/htmlspecialchars
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] replace question

2003-03-12 Thread WebDev

- Original Message -
From: WebDev [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, March 12, 2003 1:24 AM
Subject: Re: [PHP] replace question

Hello

How could I know recognize a URL in $a

$a contains often a URL   htp://www.mysite.com but as well more text

how is it possible now to recognize a URL could be in $s and if so we make
it a actual html link,  for the end user...


//   start

$a= str_replace(Dog, Cat, $b);
$a_tooklinkout =
if ($a == foundlink)
{
echo  a href=\$a_tooklinkout  $c/a;
}
else


echo $a;



// end

anybody has a tip for me ..



 Thank you all




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



Re: [PHP] replace question

2003-03-12 Thread WebDev

- Original Message -
From: WebDev [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, March 12, 2003 1:24 AM
Subject: Re: [PHP] replace question

Hello

How could I know recognize a URL in $a

$a contains often a URL   htp://www.mysite.com but as well more text

how is it possible now to recognize a URL could be in $s and if so we make
it a actual html link,  for the end user...


//   start

$a= str_replace(Dog, Cat, $b);
$a_tooklinkout =
if ($a == foundlink)
{
echo  a href=\$a_tooklinkout  $c/a;
}
else


echo $a;



// end

anybody has a tip for me ..



 Thank you all




RE: [PHP] replace question

2003-03-11 Thread John W. Holmes
 how do we replace this out of an array element
 
 ~nl~  with   nbsp;

How about str_replace()? Or are you talking about replacing that value
in each and every element in the array? If so, use array_walk() or loop
through the array and use str_replace().

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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



Re: [PHP] Replace illegal filename chars???

2002-10-24 Thread Shawn McKenzie
Doesn't work.  It returned the same as what I put in:  What's Up Doc?

-Shawn

Maxim Maletsky [EMAIL PROTECTED] wrote in message
news:20021024122630.4E99.MAXIM;php.net...

 Use a regular expression like:

 $str = ereg_replce(/[^[:alnum:]]/i, '', $str);


 --
 Maxim Maletsky
 [EMAIL PROTECTED]


 www.PHPBeginner.com  // PHP for Beginners
 www.maxim.cx // my Home

 // my Wish List: ( Get me something! )
 http://www.amazon.com/exec/obidos/registry/2IXE7SMI5EDI3



 Marek Kilimajer [EMAIL PROTECTED] wrote... :

  I use strtr() for this
 
  Shawn McKenzie wrote:
 
  Anyone have a good way to remove from a string all characters and
spaces
  that are illegal in a filename???
  
  $string = What's up Doc?;
  
  I need:
  
  $filename = whatsupdoc;
  
  TIA
  -Shawn
  
  
  
  
  
 
 
  --
  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] Replace illegal filename chars???

2002-10-24 Thread Thoenen, Peter Mr. EPS
close but preg_replace(/[^[:print:]]/,'',$str); is what you want.

The below would work but typo'ed ... ereg_replce should be ereg_replace

Also..that is just A-Za-z0-9 ... many OS's allow punctation also...[:print:]
will cover this.  

Now only if php supported [:control:] and [:graph:] :)

-Peter

 -Original Message-
 From: Shawn McKenzie [mailto:nospam;mckenzies.net]
 Sent: Friday, October 25, 2002 04:48
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Replace illegal filename chars???
 
 
 Doesn't work.  It returned the same as what I put in:  What's Up Doc?
 
 -Shawn
 
 Maxim Maletsky [EMAIL PROTECTED] wrote in message
 news:20021024122630.4E99.MAXIM;php.net...
 
  Use a regular expression like:
 
  $str = ereg_replce(/[^[:alnum:]]/i, '', $str);
 
 
  --
  Maxim Maletsky
  [EMAIL PROTECTED]
 
 
  www.PHPBeginner.com  // PHP for Beginners
  www.maxim.cx // my Home
 
  // my Wish List: ( Get me something! )
  http://www.amazon.com/exec/obidos/registry/2IXE7SMI5EDI3
 
 
 
  Marek Kilimajer [EMAIL PROTECTED] wrote... :
 
   I use strtr() for this
  
   Shawn McKenzie wrote:
  
   Anyone have a good way to remove from a string all characters and
 spaces
   that are illegal in a filename???
   
   $string = What's up Doc?;
   
   I need:
   
   $filename = whatsupdoc;
   
   TIA
   -Shawn
   
   
   
   
   
  
  
   --
   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] Replace illegal filename chars???

2002-10-24 Thread Shawn McKenzie
Thanks, the ereg_replace example didn't work for me (even after fixing the
typo).  A-Za-z0-9 is fine for my needs, replacing them with .

What is your preg_replace allowing?

Thanks!
Shawn

Peter Mr. Eps Thoenen [EMAIL PROTECTED] wrote in
message
news:A733FF9B1FB0F441B3A6209FF71030E50169B287;bondsteel2.areur.army.mil...
 close but preg_replace(/[^[:print:]]/,'',$str); is what you want.

 The below would work but typo'ed ... ereg_replce should be ereg_replace

 Also..that is just A-Za-z0-9 ... many OS's allow punctation
also...[:print:]
 will cover this.

 Now only if php supported [:control:] and [:graph:] :)

 -Peter

  -Original Message-
  From: Shawn McKenzie [mailto:nospam;mckenzies.net]
  Sent: Friday, October 25, 2002 04:48
  To: [EMAIL PROTECTED]
  Subject: Re: [PHP] Replace illegal filename chars???
 
 
  Doesn't work.  It returned the same as what I put in:  What's Up Doc?
 
  -Shawn
 
  Maxim Maletsky [EMAIL PROTECTED] wrote in message
  news:20021024122630.4E99.MAXIM;php.net...
  
   Use a regular expression like:
  
   $str = ereg_replce(/[^[:alnum:]]/i, '', $str);
  
  
   --
   Maxim Maletsky
   [EMAIL PROTECTED]
  
  
   www.PHPBeginner.com  // PHP for Beginners
   www.maxim.cx // my Home
  
   // my Wish List: ( Get me something! )
   http://www.amazon.com/exec/obidos/registry/2IXE7SMI5EDI3
  
  
  
   Marek Kilimajer [EMAIL PROTECTED] wrote... :
  
I use strtr() for this
   
Shawn McKenzie wrote:
   
Anyone have a good way to remove from a string all characters and
  spaces
that are illegal in a filename???

$string = What's up Doc?;

I need:

$filename = whatsupdoc;

TIA
-Shawn





   
   
--
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] Replace linefeed/newline from text inputs with br tag?

2002-09-23 Thread David T-G

John, et al --

...and then John Holmes said...
% 
%  If i have a textarea form input for users and they enter in return
% spaces,
%  how can i replace the ascci chars with html tags?
% 
% It'd be great if they had a function for this...they could call it
% nl2br() or something...

Yeah.  It would be even cooler if that's what it did, eh?  Maybe someone
should rename that nl2nl+br and write a *real* nl2br for those of us that
want to GET RID OF the newlines.  I think that part of the reason this
question comes up often is because nl2br doesn't really do what its name
would lead us, or at least me, to think that it does.

Patrick, I just went through this a few weeks ago (Sep 06).  I don't know
that the list has archives, or I'd send you there first (anyone with a
URL?), so all I can do is give you my result:

  $fout = ereg_replace((\n|\r)+,br,$fin) ;

This translates any newline and/or carriage return in your $fin string to
a br and puts the results in $fout.  It will convert input like

  this is
  some input

to

  this isbrsome input

and you no longer have a newline in the way.  The only downside is that

  this is

  some input

ends up the same way because the regexp is greedy, but the upside is that
it will work for UNIX (\n), Mac (\r), and DOS/Win (\r\n) input.


HTH  HAND

:-D
-- 
David T-G  * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg!




msg79522/pgp0.pgp
Description: PGP signature


RE: [PHP] Replace linefeed/newline from text inputs with br tag?

2002-09-23 Thread John Holmes

Okay, you got me on that one, but why do you need to remove the
newlines? It should be stored in the database (if you're doing so) with
the  newlines and not the HTML breaks. You only use the nl2br() to
output it on a web page, so who cares if the new lines are still there?

The manual page explains this correctly, btw. It says that a br /
will be inserted before all newlines.

---John Holmes...

 -Original Message-
 From: David T-G [mailto:[EMAIL PROTECTED]]
 Sent: Monday, September 23, 2002 7:10 AM
 To: PHP General list
 Cc: John Holmes; 'Patrick Lebon'
 Subject: Re: [PHP] Replace linefeed/newline from text inputs with br
 tag?
 
 John, et al --
 
 ...and then John Holmes said...
 %
 %  If i have a textarea form input for users and they enter in return
 % spaces,
 %  how can i replace the ascci chars with html tags?
 %
 % It'd be great if they had a function for this...they could call it
 % nl2br() or something...
 
 Yeah.  It would be even cooler if that's what it did, eh?  Maybe
someone
 should rename that nl2nl+br and write a *real* nl2br for those of us
that
 want to GET RID OF the newlines.  I think that part of the reason this
 question comes up often is because nl2br doesn't really do what its
name
 would lead us, or at least me, to think that it does.
 
 Patrick, I just went through this a few weeks ago (Sep 06).  I don't
know
 that the list has archives, or I'd send you there first (anyone with a
 URL?), so all I can do is give you my result:
 
   $fout = ereg_replace((\n|\r)+,br,$fin) ;
 
 This translates any newline and/or carriage return in your $fin string
to
 a br and puts the results in $fout.  It will convert input like
 
   this is
   some input
 
 to
 
   this isbrsome input
 
 and you no longer have a newline in the way.  The only downside is
that
 
   this is
 
   some input
 
 ends up the same way because the regexp is greedy, but the upside is
that
 it will work for UNIX (\n), Mac (\r), and DOS/Win (\r\n) input.
 
 
 HTH  HAND
 
 :-D
 --
 David T-G  * It's easier to fight for one's
principles
 (play) [EMAIL PROTECTED] * than to live up to them. -- fortune
 cookie
 (work) [EMAIL PROTECTED]
 http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl
 Npg!



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




Re: [PHP] Replace linefeed/newline from text inputs with br tag?

2002-09-23 Thread David T-G

John, et al --

...and then John Holmes said...
% 
% Okay, you got me on that one, but why do you need to remove the

In my case, I had a newline-delimited file of

  field@@data
  field@@data
  field@@data

and when the data had an embedded newline like

  comment@@this is a
  long comment
  field@@data

then it messed things up.  Yeah, I learned about the possibility of using
XML along the way, and I've already thought about serialize and base64
(which I *do* use inside the code, though not out in the file) for simple
protections, but a requirement was that the text file also be readable
and editable by people -- and, besides, I'm just extending this code
rather than writing it :-)


% newlines? It should be stored in the database (if you're doing so) with
% the  newlines and not the HTML breaks. You only use the nl2br() to
% output it on a web page, so who cares if the new lines are still there?

For output, it doesn't matter, as you say.  My problem was input :-)


% 
% The manual page explains this correctly, btw. It says that a br /
% will be inserted before all newlines.

Yeah, but that requires actual reading ;-)  Who knows any more what TFM is?


% 
% ---John Holmes...


HTH  HAND

:-D
-- 
David T-G  * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg!




msg79529/pgp0.pgp
Description: PGP signature


RE: [PHP] Replace linefeed/newline from text inputs with br tag?

2002-09-22 Thread John Holmes

 If i have a textarea form input for users and they enter in return
spaces,
 how can i replace the ascci chars with html tags?

It'd be great if they had a function for this...they could call it
nl2br() or something...

www.php.net/nl2br

---John Holmes...


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




Re: [PHP] Replace

2002-08-16 Thread Jason Reid

str_replace is your friend in this situation

Jason Reid
[EMAIL PROTECTED]
--
AC Host Canada
www.achost.ca

- Original Message - 
From: Alexander Lindstedt [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, August 16, 2002 6:05 PM
Subject: [PHP] Replace


 If i want to find just a word in a variable, and then replace just that
 specific word... is there any simple way to do 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] replace question

2002-05-06 Thread Josh Valerie McCormack

(This is more info on the question I asked before)

Here's the text file (text.txt):
   This is a test of the templating program.
   Here's hoping it's working!
   John Smith

Here's one line from the CSV file (new_data.csv):
John,Smith,4770 Rosepetal Ct., Richmond, VA 22032 USA,(703) 
978-4472,0/0/00,


And here's the code I have (merge.php):

  1 ?
  2 $row = 1;
  3
  4 $text   = fopen(text.txt, r);
  5 $merged = fopen(merged_text.html, w);
  6 $fp = fopen(new_data.csv, r);
  7
  8 $filecontents = fread($text,filesize(text.txt));
  9
 10 while ($data = fgetcsv ($fp, 1000, ,)) {
 11 $num = count ($data);
 12 $row++;
 13 for ($c=0; $c  $num; $c++) {
 14 $fullname = $data[0] .   . $data[1];
 15 $newfullname = a 
href=.$fullname..$fullname./a;
 16 $newfilecontents = 
str_replace($fullname,$newfullname,$filecontents);
 17
 18 fwrite($merged,$newfilecontents);
 19 }
 20 }
 21 echo nl2br($newfilecontents);
 22 // fwrite($merged,$newfilecontents);
 23 fclose ($fp);
 24 fclose ($merged);
 25 fclose ($text);
 26 ?


Josh



Miguel Cruz wrote:

On Sun, 5 May 2002, Josh  Valerie McCormack wrote:

I'm iterating through a CSV file pulling in rows as arrays with fgetcsv 
and I'd like to search for patterns made up of the first two array items 
of each row with a space between them in a text file, and make them into 
links. I can't figure out how to do this, could someone help?


How about posting a sample row or two along with how you want the data to
appear after the transformation?

miguel





RE: [PHP] replace question

2002-05-05 Thread John Holmes

Are you having trouble pulling the data out of the file, or creating the
link? Do you want a link created for every row? What is the makeup of
the file? Is array[0] the URL, and array[1] the desription? If it's just
the link you need, that's easy...

echo a href=' . $array[0] . ' . $array[1] . /a;

---John Holmes...

 -Original Message-
 From: Josh  Valerie McCormack [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, May 05, 2002 8:23 AM
 To: PHP-General
 Subject: [PHP] replace question
 
 I'm iterating through a CSV file pulling in rows as arrays with
fgetcsv
 and I'd like to search for patterns made up of the first two array
items
 of each row with a space between them in a text file, and make them
into
 links. I can't figure out how to do this, could someone help?
 
 Josh
 
 
 --
 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] replace question

2002-05-05 Thread Miguel Cruz

On Sun, 5 May 2002, Josh  Valerie McCormack wrote:
 I'm iterating through a CSV file pulling in rows as arrays with fgetcsv 
 and I'd like to search for patterns made up of the first two array items 
 of each row with a space between them in a text file, and make them into 
 links. I can't figure out how to do this, could someone help?

How about posting a sample row or two along with how you want the data to
appear after the transformation?

miguel


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




Re: [PHP] replace digits

2002-03-18 Thread mnc

On Mon, 18 Mar 2002, Marc Bleuler wrote:
 Im trying to replace the first two digits (41) from a telephone no. with a 0
 (zero), like 41763334455 should end wit 0763334455. Anybody a idea howto? My
 php programming experiance is not very high so if any body could provide a
 code example

http://www.php.net/manual/en/function.ereg-replace.php

  $new_number = ereg_replace('^41', '0', $old_number);

miguel


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




  1   2   >