php-general Digest 2 Feb 2007 20:53:00 -0000 Issue 4604

Topics (messages 248184 through 248209):

Graphs
        248184 by: ffredrixson.comcast.net
        248185 by: Thomas Pedoussaut
        248192 by: LeaseWeb - Poelwijk

Login script login
        248186 by: Dave Carrera
        248187 by: Satyam
        248188 by: Stut
        248189 by: Dave Carrera
        248190 by: Németh Zoltán
        248191 by: Jürgen Wind

Reading from the htpasswd file
        248193 by: Ryan A

Year
        248194 by: Dan Shirah
        248195 by: Robert Cummings
        248196 by: Robert Cummings
        248197 by: Németh Zoltán
        248198 by: chetan rane
        248199 by: Dan Shirah

Re: Can a class instance a property of another class
        248200 by: Ken Kixmoeller -- reply to ken.kixmoeller.com

Executing scripts from a table
        248201 by: Ken Kixmoeller -- reply to ken.kixmoeller.com
        248202 by: Ken Kixmoeller -- reply to ken.kixmoeller.com

preg_replace();
        248203 by: Sébastien WENSKE
        248204 by: wwww.freenet.am
        248205 by: wwww.freenet.am
        248206 by: wwww.freenet.am
        248207 by: Steffen Ebermann

Re: preg_replace(); [solved]
        248208 by: Sébastien WENSKE
        248209 by: Steffen Ebermann

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
I would like to add some graphing capability to an app of mine. What package is 
recommended? I don't need anything too fancy, just some bar graphs, pie charts, 
etc.

Thank you in advance.

--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
I would like to add some graphing capability to an app of mine. What package is 
recommended? I don't need anything too fancy, just some bar graphs, pie charts, 
etc.

Thank you in advance.
I use the PEAR module Image_Graph
Officially it's still in alpha, but works like a charm.

--
Thomas

--- End Message ---
--- Begin Message --- Or you could try JPgraph, i used it for several projects: http://www.aditus.nu/jpgraph/

Regards,

Sander Poelwijk



[EMAIL PROTECTED] wrote:
I would like to add some graphing capability to an app of mine. What package is 
recommended? I don't need anything too fancy, just some bar graphs, pie charts, 
etc.

Thank you in advance.

--- End Message ---
--- Begin Message ---
Hi All,

Having a grey brain moment here and need some advise on the logic of this, should be simple, login script.

I am checking validity of

customer number
customer email
customer password (md5 in mysql)

So i have my form with relevant fields

Now i am getting problems with either sql or how i am handling , and showing, and errors.....

I think what i am asking is this

If someone just hits the login button show error "All fields must be entered"

If customer number dose not excist show relevant error

If customer number ok but email not show error

If customer number ok but email ok but password is not show error

If all is ok set sessions, got this ok, and proceed.

Any help with with this is very much appreciated.

Kind Regards

Dave C

--- End Message ---
--- Begin Message --- ----- Original Message ----- From: "Dave Carrera" <[EMAIL PROTECTED]>
Hi All,

Having a grey brain moment here and need some advise on the logic of this, should be simple, login script.

I am checking validity of

customer number
customer email
customer password (md5 in mysql)

So i have my form with relevant fields

Now i am getting problems with either sql or how i am handling , and showing, and errors.....

I think what i am asking is this

If someone just hits the login button show error "All fields must be entered"

If customer number dose not excist show relevant error

If customer number ok but email not show error

If customer number ok but email ok but password is not show error


In login scripts you usually don't tell which part of the login is wrong, otherwise, you are hinting at what is right. Once the customer is logged in, you are right to be as helpful as possible, but until the customer proves who he/she is, you don't give away anything.

Satyam


If all is ok set sessions, got this ok, and proceed.

Any help with with this is very much appreciated.

Kind Regards

Dave C

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



--- End Message ---
--- Begin Message ---
Dave Carrera wrote:
Hi All,

Having a grey brain moment here and need some advise on the logic of this, should be simple, login script.

I am checking validity of

customer number
customer email
customer password (md5 in mysql)

So i have my form with relevant fields

Now i am getting problems with either sql or how i am handling , and showing, and errors.....

I think what i am asking is this

If someone just hits the login button show error "All fields must be entered"

If customer number dose not excist show relevant error

If customer number ok but email not show error

If customer number ok but email ok but password is not show error

If all is ok set sessions, got this ok, and proceed.

Any help with with this is very much appreciated.

Kind Regards

Dave C

I'm not totally clear what the question was in there. Personally I keep this simple...

<?php
$_POST['number'] =
        (isset($_POST['number']) ? trim($_POST['number']) : '');
$_POST['email'] =
        (isset($_POST['email']) ? trim($_POST['email']) : '');

if (empty($_POST['number']) or
    empty($_POST['email']) or
    empty($_POST['password']))
{
    die('All fields must be entered');
}

// Find the customer/user/whatever you need from the given details

if (<<not found>>)
{
    die('Unable to locate customer/user/whatever');
}

// Set up the session here, or however you're tracking the
// current customer/user/whatever

header('Location: /somewhere_else');
?>

Hope that helps.

-Stut

--- End Message ---
--- Begin Message ---
Hi Stut,

I think i have found where i am going wrong.....

Its in the comparison login for the db result.

So i select * from jfjfjfjf where custno=$_POST[number]

But now i am getting messed up with if cust no not found then all i get is a blank page but hoping for an error

And i dont think i am comparing the db result with the $_POST correctly

Struggling here a bit :-(

Dave C

Stut wrote:
Dave Carrera wrote:
Hi All,

Having a grey brain moment here and need some advise on the logic of this, should be simple, login script.

I am checking validity of

customer number
customer email
customer password (md5 in mysql)

So i have my form with relevant fields

Now i am getting problems with either sql or how i am handling , and showing, and errors.....

I think what i am asking is this

If someone just hits the login button show error "All fields must be entered"

If customer number dose not excist show relevant error

If customer number ok but email not show error

If customer number ok but email ok but password is not show error

If all is ok set sessions, got this ok, and proceed.

Any help with with this is very much appreciated.

Kind Regards

Dave C

I'm not totally clear what the question was in there. Personally I keep this simple...

<?php
$_POST['number'] =
        (isset($_POST['number']) ? trim($_POST['number']) : '');
$_POST['email'] =
        (isset($_POST['email']) ? trim($_POST['email']) : '');

if (empty($_POST['number']) or
    empty($_POST['email']) or
    empty($_POST['password']))
{
    die('All fields must be entered');
}

// Find the customer/user/whatever you need from the given details

if (<<not found>>)
{
    die('Unable to locate customer/user/whatever');
}

// Set up the session here, or however you're tracking the
// current customer/user/whatever

header('Location: /somewhere_else');
?>

Hope that helps.

-Stut


--- End Message ---
--- Begin Message ---
On p, 2007-02-02 at 12:10 +0000, Dave Carrera wrote:
> Hi Stut,
> 
> I think i have found where i am going wrong.....
> 
> Its in the comparison login for the db result.
> 
> So i select * from jfjfjfjf where custno=$_POST[number]
> 
> But now i am getting messed up with if cust no not found then all i get 
> is a blank page but hoping for an error

because you get an empty result set if no match is found
so check it like

if ($row = mysql_fetch_array($result)) {
 // ok, found
} else {
 // not found, error
}

or whatever sql you use

hope that helps
Zoltán Németh

> 
> And i dont think i am comparing the db result with the $_POST correctly
> 
> Struggling here a bit :-(
> 
> Dave C
> 
> Stut wrote:
> > Dave Carrera wrote:
> >> Hi All,
> >>
> >> Having a grey brain moment here and need some advise on the logic of 
> >> this, should be simple, login script.
> >>
> >> I am checking validity of
> >>
> >> customer number
> >> customer email
> >> customer password (md5 in mysql)
> >>
> >> So i have my form with relevant fields
> >>
> >> Now i am getting problems with either sql or how i am handling , and 
> >> showing, and errors.....
> >>
> >> I think what i am asking is this
> >>
> >> If someone just hits the login button show error "All fields must be 
> >> entered"
> >>
> >> If customer number dose not excist show relevant error
> >>
> >> If customer number ok but email not show error
> >>
> >> If customer number ok but email ok but password is not show error
> >>
> >> If all is ok set sessions, got this ok, and proceed.
> >>
> >> Any help with with this is very much appreciated.
> >>
> >> Kind Regards
> >>
> >> Dave C
> >
> > I'm not totally clear what the question was in there. Personally I 
> > keep this simple...
> >
> > <?php
> > $_POST['number'] =
> >         (isset($_POST['number']) ? trim($_POST['number']) : '');
> > $_POST['email'] =
> >         (isset($_POST['email']) ? trim($_POST['email']) : '');
> >
> > if (empty($_POST['number']) or
> >     empty($_POST['email']) or
> >     empty($_POST['password']))
> > {
> >     die('All fields must be entered');
> > }
> >
> > // Find the customer/user/whatever you need from the given details
> >
> > if (<<not found>>)
> > {
> >     die('Unable to locate customer/user/whatever');
> > }
> >
> > // Set up the session here, or however you're tracking the
> > // current customer/user/whatever
> >
> > header('Location: /somewhere_else');
> > ?>
> >
> > Hope that helps.
> >
> > -Stut
> >
> 

--- End Message ---
--- Begin Message ---


Stut wrote:
> 
> 
> 
> I'm not totally clear what the question was in there. Personally I keep 
> this simple...
> 
> <?php
> $_POST['number'] =
>          (isset($_POST['number']) ? trim($_POST['number']) : '');
> $_POST['email'] =
>          (isset($_POST['email']) ? trim($_POST['email']) : '');
> 
> if (empty($_POST['number']) or
>      empty($_POST['email']) or
>      empty($_POST['password']))
> {
>      die('All fields must be entered');
> }
> 
> // Find the customer/user/whatever you need from the given details
> 
> if (<<not found>>)
> {
>      die('Unable to locate customer/user/whatever');
> }
> 
> // Set up the session here, or however you're tracking the
> // current customer/user/whatever
> 
> header('Location: /somewhere_else');
> ?>
> 
> Hope that helps.
> 
> -Stut
> 
> 
be aware that you need a session_write_close(); before header('Location...
or the session data might not be written to disk!

just my 2 cent
-- 
View this message in context: 
http://www.nabble.com/Login-script-login-tf3160341.html#a8766588
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
Hey,

*** Warning: feeling a bit braindead today after working long hours yesterday 
so please excuse if some parts are crappy***

I have a pal who uses a htpasswd file for access to his site..

rather than using basic_auth he wants to change it to form based _without_ a DB 
(ie user comes to his site and enters the username and password into a form, 
then submits it to the php script, the php script reads the htpasswd file and 
accordingly grants access or denies access if the login does not match)

Am not so sure about this but before i can make an arguement against this, I 
should know something myself so my questions to you more knowledgeable guys are:
1. Is it such a good idea switching?
2.Wont the basic_auth pop up anyway even after entering these values into the 
form?
3. If having a hundreds (or even thousands) of user:pass combinations in the 
htpasswd file.... wont it make logging in longer and more processor intensive 
to search all of the combinations till you find (or not find) the login?


Did some small code experiments before coming here asking for advise...
can send you the code I have written if need be...but what i have found out is 
with small amounts of data i see no difference in speed of loggin in using the 
htpasswd file as the "login database"..

Thanks for any input on the above.

Cheers!
R


------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
 
---------------------------------
Sucker-punch spam with award-winning protection.
 Try the free Yahoo! Mail Beta.

--- End Message ---
--- Begin Message ---
Hello all,

I am trying to populate a dropdown list to contain the current year to 10
years in the future.  Below is the code I'm using:

<?PHP
 for ($y=0;$y<=10;$y++) {
 $years=date <http://php.net/date>('Y')+$y;
 $short_years=date <http://php.net/date>('y')+$y;
 echo "$short_years";
 echo "<option value=\"$short_years\">$years</option>";
 }
?>
I want the selection value to be 2007, 2008, 2009, 2010....  and the $years
accomplishes this.  Howeverm I want the option value to be the two digit
year ex. 07, 08, 09, 10...the $short_years semi accomplishes this....instead
of getting 07, 08, 08, 10 I get 7, 8, 9, 10...how can I get it to output the
two year for 07, 08, 09 without it cutting off the zero?

Reagrds,

Dan

--- End Message ---
--- Begin Message ---
On Fri, 2007-02-02 at 10:11 -0500, Dan Shirah wrote:
> Hello all,
> 
> I am trying to populate a dropdown list to contain the current year to 10
> years in the future.  Below is the code I'm using:
> 
> <?PHP
>   for ($y=0;$y<=10;$y++) {
>   $years=date <http://php.net/date>('Y')+$y;
>   $short_years=date <http://php.net/date>('y')+$y;
>   echo "$short_years";
>   echo "<option value=\"$short_years\">$years</option>";
>   }
> ?>
> I want the selection value to be 2007, 2008, 2009, 2010....  and the $years
> accomplishes this.  Howeverm I want the option value to be the two digit
> year ex. 07, 08, 09, 10...the $short_years semi accomplishes this....instead
> of getting 07, 08, 08, 10 I get 7, 8, 9, 10...how can I get it to output the
> two year for 07, 08, 09 without it cutting off the zero?

<?php

$year = date( 'Y' );
for( $i = 0; $i < 10; $i++ )
{
    $iYear = substr( (string)($year + 1), 2 );
    echo '<option value="'.$iYear.'">'.$iYear.'</option>';
}

?>

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.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
On Fri, 2007-02-02 at 10:21 -0500, Robert Cummings wrote:
> On Fri, 2007-02-02 at 10:11 -0500, Dan Shirah wrote:
> > Hello all,
> > 
> > I am trying to populate a dropdown list to contain the current year to 10
> > years in the future.  Below is the code I'm using:
> > 
> > <?PHP
> >   for ($y=0;$y<=10;$y++) {
> >   $years=date <http://php.net/date>('Y')+$y;
> >   $short_years=date <http://php.net/date>('y')+$y;
> >   echo "$short_years";
> >   echo "<option value=\"$short_years\">$years</option>";
> >   }
> > ?>
> > I want the selection value to be 2007, 2008, 2009, 2010....  and the $years
> > accomplishes this.  Howeverm I want the option value to be the two digit
> > year ex. 07, 08, 09, 10...the $short_years semi accomplishes this....instead
> > of getting 07, 08, 08, 10 I get 7, 8, 9, 10...how can I get it to output the
> > two year for 07, 08, 09 without it cutting off the zero?
> 
> <?php
> 
> $year = date( 'Y' );
> for( $i = 0; $i < 10; $i++ )
> {
>     $iYear = substr( (string)($year + 1), 2 );
>     echo '<option value="'.$iYear.'">'.$iYear.'</option>';
> }
> 
> ?>

Bleh... Typo in the above... so here's a better one :)

<?php

$currYear = date( 'Y' );
for( $i = 0; $i < 10; $i++ )
{
    $longYear  = $currYear + $i;
    $shortYear = substr( (string)$longYear, 2 );
    echo '<option value="'.$shortYear.'">'.$longYear.'</option>';
}

?>

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.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
On p, 2007-02-02 at 10:11 -0500, Dan Shirah wrote:
> Hello all,
> 
> I am trying to populate a dropdown list to contain the current year to 10
> years in the future.  Below is the code I'm using:
> 
> <?PHP
>   for ($y=0;$y<=10;$y++) {
>   $years=date <http://php.net/date>('Y')+$y;
>   $short_years=date <http://php.net/date>('y')+$y;
>   echo "$short_years";
>   echo "<option value=\"$short_years\">$years</option>";
>   }
> ?>
> I want the selection value to be 2007, 2008, 2009, 2010....  and the $years
> accomplishes this.  Howeverm I want the option value to be the two digit
> year ex. 07, 08, 09, 10...the $short_years semi accomplishes this....instead
> of getting 07, 08, 08, 10 I get 7, 8, 9, 10...how can I get it to output the
> two year for 07, 08, 09 without it cutting off the zero?

I think it is because when you calculate $short_years it is an integer.
So insert the following before echoing it out:

if ($short_years < 10) {$short_years = "0" . $short_years;}

hope that helps
Zoltán Németh

> 
> Reagrds,
> 
> Dan

--- End Message ---
--- Begin Message ---
HI Dan

try this this should work 100%;

echo "<select>";
for ($y=0;$y<=10;$y++) {
$years=date('Y')+$y;
$short_years=date('y')+$y;
printf("<option value=\"%02d\">%d</option>",$short_years,$years);

}
echo "</select>";

On 2/2/07, Dan Shirah <[EMAIL PROTECTED]> wrote:

Hello all,

I am trying to populate a dropdown list to contain the current year to 10
years in the future.  Below is the code I'm using:

<?PHP
  for ($y=0;$y<=10;$y++) {
  $years=date <http://php.net/date>('Y')+$y;
  $short_years=date <http://php.net/date>('y')+$y;
  echo "$short_years";
  echo "<option value=\"$short_years\">$years</option>";
  }
?>
I want the selection value to be 2007, 2008, 2009, 2010....  and the
$years
accomplishes this.  Howeverm I want the option value to be the two digit
year ex. 07, 08, 09, 10...the $short_years semi accomplishes
this....instead
of getting 07, 08, 08, 10 I get 7, 8, 9, 10...how can I get it to output
the
two year for 07, 08, 09 without it cutting off the zero?

Reagrds,

Dan




--
Have A plesant Day
Chetan. D. Rane
Location: Pune , India
Contact: +91-9890792762
otherID: [EMAIL PROTECTED]
            [EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Thanks everyone!  A lot of great solutions!

On 2/2/07, chetan rane <[EMAIL PROTECTED]> wrote:

HI Dan

try this this should work 100%;

echo "<select>";
for ($y=0;$y<=10;$y++) {
$years=date('Y')+$y;
$short_years=date('y')+$y;
printf("<option value=\"%02d\">%d</option>",$short_years,$years);

}
echo "</select>";

On 2/2/07, Dan Shirah <[EMAIL PROTECTED]> wrote:
>
> Hello all,
>
> I am trying to populate a dropdown list to contain the current year to
10
> years in the future.  Below is the code I'm using:
>
> <?PHP
>   for ($y=0;$y<=10;$y++) {
>   $years=date <http://php.net/date>('Y')+$y;
>   $short_years=date <http://php.net/date>('y')+$y;
>   echo "$short_years";
>   echo "<option value=\"$short_years\">$years</option>";
>   }
> ?>
> I want the selection value to be 2007, 2008, 2009, 2010....  and the
> $years
> accomplishes this.  Howeverm I want the option value to be the two digit
> year ex. 07, 08, 09, 10...the $short_years semi accomplishes
> this....instead
> of getting 07, 08, 08, 10 I get 7, 8, 9, 10...how can I get it to output
> the
> two year for 07, 08, 09 without it cutting off the zero?
>
> Reagrds,
>
> Dan
>



--
Have A plesant Day
Chetan. D. Rane
Location: Pune , India
Contact: +91-9890792762
otherID: [EMAIL PROTECTED]
            [EMAIL PROTECTED]



--- End Message ---
--- Begin Message --- Thanks to all -- got all of this working fine. Mostly my syntax was a bit off. Your examples helped me mend my ways.

Ken

--- End Message ---
--- Begin Message ---
Hi, folks -- - -

For security and efficiency, I am trying to store PHP scripts in MySQL tables. Only problem: I can't get them to execute.

In a template:
----------------------------------------
$php_code = $this->ApplicationObject->GetStoredCode($whichpage);

echo $php_code;  // doesn't execute

print_r($php_code); // doesn't execute, either
----------------------------------------

I've looked for some kind of exec_script() function without luck.

I can't be the first one to have done this. Any ideas or resources you can point me to?

Thank you -- - -

Ken

--- End Message ---
--- Begin Message ---
Yeah, that was it. Thanks, Thomas.

(dang it, I should have been able to figure out that myself!)

Ken


On Feb 2, 2007, at 11:32 AM, Thomas Pedoussaut wrote:

Ken Kixmoeller -- reply to [EMAIL PROTECTED] wrote:
Hi, folks -- - -

For security and efficiency, I am trying to store PHP scripts in MySQL tables. Only problem: I can't get them to execute.

In a template:
----------------------------------------
$php_code = $this->ApplicationObject->GetStoredCode($whichpage);

echo $php_code;  // doesn't execute

print_r($php_code); // doesn't execute, either
----------------------------------------

I think you're thinking of eval()
http://ie2.php.net/manual/en/function.eval.php

It should do what you want.

--
Thomas



--- End Message ---
--- Begin Message ---
Hi all,

I want replace the "|" (pipe) and the " " (space) chars where are between " 
(double-quotes)  by an underscore "_" with the preg_replace(); funtction.

Can someone help me to find the correct regex.

Thanks in advance

Seb

--- End Message ---
--- Begin Message ---
I am not a very experienced programmer, but I think that "str_replace"
can be used in this case:
$new_string=str_replace('|', '_', $old_string)

then use the same function to replace spaces.

Ed

Friday, February 2, 2007, 9:30:37 PM, you wrote:

> Hi all,

> I want replace the "|" (pipe) and the " " (space) chars where are
> between " (double-quotes)  by an underscore "_" with the
> preg_replace(); funtction.

> Can someone help me to find the correct regex.

> Thanks in advance

> Seb



-- 
Best regards,
 wwww                            mailto:[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
I have tasted the code and it worked fine (if I got you right):

$old_string="lazy \"|\" dog";
$new_string=str_replace('"|"', '_', $old_string);
print $new_string;

I got "lazy_dog"

Ed

Friday, February 2, 2007, 10:01:14 PM, you wrote:

> Thanks,

> but I think that I must use preg_replace because the condition is: replace
> the chars (pipe or space) when they are between "

> ie :  src=file:///h|/hjcjdgh dlkgj/dgjk.jpg"  to 
> src=file:///h_/hjcjdgh_dlkgj/dgjk.jpg"

> Seb





> ----- Original Message ----- 
> From: <[EMAIL PROTECTED]>
> To: "Sébastien WENSKE" <[EMAIL PROTECTED]>
> Cc: <php-general@lists.php.net>
> Sent: Friday, February 02, 2007 8:38 PM
> Subject: Re: [PHP] preg_replace();


> I am not a very experienced programmer, but I think that "str_replace"
> can be used in this case:
> $new_string=str_replace('|', '_', $old_string)

> then use the same function to replace spaces.

> Ed

> Friday, February 2, 2007, 9:30:37 PM, you wrote:

>> Hi all,

>> I want replace the "|" (pipe) and the " " (space) chars where are
>> between " (double-quotes)  by an underscore "_" with the
>> preg_replace(); funtction.

>> Can someone help me to find the correct regex.

>> Thanks in advance

>> Seb

--- End Message ---
--- Begin Message ---
Try this one:

$old_string="lazy \"some chars|some chars\" dog";
$new_string=str_replace('|', '_', $old_string);
print $new_string;

Ed

Friday, February 2, 2007, 10:39:59 PM, you wrote:

> ok, but :

> $old_string="lazy \"some chars|some chars\" dog";
> $new_string=str_replace('"|"', '_', $old_string);

> don't work

> sorry for my bad english, i'm french.

> ----- Original Message ----- 
> From: <[EMAIL PROTECTED]>
> To: "Sébastien WENSKE" <[EMAIL PROTECTED]>
> Sent: Friday, February 02, 2007 9:22 PM
> Subject: Re[2]: [PHP] preg_replace();


> I have tasted the code and it worked fine (if I got you right):

> $old_string="lazy \"|\" dog";
> $new_string=str_replace('"|"', '_', $old_string);
> print $new_string;

> I got "lazy_dog"

> Ed

> Friday, February 2, 2007, 10:01:14 PM, you wrote:

>> Thanks,

>> but I think that I must use preg_replace because the condition is: replace
>> the chars (pipe or space) when they are between "

>> ie :  src=file:///h|/hjcjdgh dlkgj/dgjk.jpg"  to
>> src=file:///h_/hjcjdgh_dlkgj/dgjk.jpg"

>> Seb





>> ----- Original Message ----- 
>> From: <[EMAIL PROTECTED]>
>> To: "Sébastien WENSKE" <[EMAIL PROTECTED]>
>> Cc: <php-general@lists.php.net>
>> Sent: Friday, February 02, 2007 8:38 PM
>> Subject: Re: [PHP] preg_replace();


>> I am not a very experienced programmer, but I think that "str_replace"
>> can be used in this case:
>> $new_string=str_replace('|', '_', $old_string)

>> then use the same function to replace spaces.

>> Ed

>> Friday, February 2, 2007, 9:30:37 PM, you wrote:

>>> Hi all,

>>> I want replace the "|" (pipe) and the " " (space) chars where are
>>> between " (double-quotes)  by an underscore "_" with the
>>> preg_replace(); funtction.

>>> Can someone help me to find the correct regex.

>>> Thanks in advance

>>> Seb

--- End Message ---
--- Begin Message ---
This always works for me:

if (preg_match_all("!\"(.+)\"!sU", $var, $match))
{
  for ($i=0; $i<count($match[0]); $i++)
  {
    $old = $match[1][$i];
    $new = preg_replace("!\|| !", "_", $old);
    $var = str_replace("\"$old\"", "\"$new\"", $var);
  }
}


On Fri, Feb 02, 2007 at 07:30:37PM +0100, Sébastien WENSKE wrote:
> Hi all,
> 
> I want replace the "|" (pipe) and the " " (space) chars where are between " 
> (double-quotes)  by an underscore "_" with the preg_replace(); funtction.
> 
> Can someone help me to find the correct regex.
> 
> Thanks in advance
> 
> Seb

--- End Message ---
--- Begin Message ---
nice !

thanks Steffen & Ed !

i've just add '[src|background] *= *' to make sure that the replacement takes effect only in THML tag's attributes

if (preg_match_all("![src|background] *= *\"(.+)\"!sU", $htmlContent, $match))
{
 for ($i=0; $i<count($match[0]); $i++)
 {
   $old = $match[1][$i];
   $new = preg_replace("!\|| !", "_", $old);
   $htmlContent = str_replace("\"$old\"", "\"$new\"", $htmlContent);
 }
}

----- Original Message ----- From: "Steffen Ebermann" <[EMAIL PROTECTED]>
To: <php-general@lists.php.net>
Cc: "Sébastien WENSKE" <[EMAIL PROTECTED]>
Sent: Friday, February 02, 2007 9:01 PM
Subject: Re: [PHP] preg_replace();


This always works for me:

if (preg_match_all("!\"(.+)\"!sU", $var, $match))
{
 for ($i=0; $i<count($match[0]); $i++)
 {
   $old = $match[1][$i];
   $new = preg_replace("!\|| !", "_", $old);
   $var = str_replace("\"$old\"", "\"$new\"", $var);
 }
}


On Fri, Feb 02, 2007 at 07:30:37PM +0100, Sébastien WENSKE wrote:
Hi all,

I want replace the "|" (pipe) and the " " (space) chars where are between " (double-quotes) by an underscore "_" with the preg_replace(); funtction.

Can someone help me to find the correct regex.

Thanks in advance

Seb


--- End Message ---
--- Begin Message ---
Maybe you just mistyped that, but this would *probably* also match on s=""
or bar="", cause [ and ] are metacharacters.

--- End Message ---

Reply via email to