RE: [PHP] Re: Vars inside an sql query [Regular expression question]

2003-06-12 Thread Monu Ogbe
Hi, 

I'll join the conversation, because I have a similar problem.  

PHP "interpolates" variable values in strings if these are enclosed in 
double quotes:

e.g., 

  $string = "select * FROM `table` where id='$value' order by name";

PHP does not interpolate variables contained in strings delimited by 
single quotes.  That much is clear.

What seems to happen in Ben's case is that strings retrieved from the 
database are treated as if they are delimited by single quotes.

I have the same trouble in the case of strings retrieved from a file.

I have not been able to find a function that FORCES the variables 
within a single-quoted string to be translated.

I am currently looking into "heredocs" because the heredoc construct, 
like double-quoted strings, does perform interpolation.

I'll report back if this works, but would love to hear if there is a
simpler solution.

Thanks, 

Monu

>Sorry this is more correct :
>
>-- starting query.php
>select * FROM `table` where id='$value' order by name
>-- ending query.php
>
>"Hatem Ben" <[EMAIL PROTECTED]> a écrit dans le message de news:
>[EMAIL PROTECTED]
>> Oh, ok this is how i want to do it exactly :
>>  query.php
>> > $query = "select * FROM `table` where id='$value' order by name";
>> ?>
>>
>>  parse.php
>> > $fcontents = join('' , file('query.php'));
>> preg_match_all("/^('\$(.*)')/si", $fcontents,$matches);
>> print_r($matches)
>> ?>
>>
>> Thanks
>>
>> "Chris Hayes" <[EMAIL PROTECTED]> a écrit dans le message de news:
>> [EMAIL PROTECTED]
>> > At 13:54 12-6-03, you wrote:
>> > >>I got a headache doing this, i need to get vars inside an sql
query.
>For
>> > >>example :
>> > >>
>> > >>$query = "select * FROM `table` where id='$value' order by name";
>> > >>preg_match_all("/^('\$(.*)')/si", $query,$matches);
>> >
>> >
>> > >That doesn't work as the new string already is like "select * FROM
>> `table`
>> > >where id='2' order by name" assuming $value was 2...
>> >
>> > True, so try using
>> >
>> > $query = "select * FROM `table` where id='__VALUE__' order by
name";
>> >
>> > if you insist on doing it this way.
>> >
>> > If you decide to keep trying with the $value, you need to know that
>> > variables inside "double quotes" are entered on the spot, while not
so
>> with
>> > 'single quotes'.
>> >
>> >
>> > Also it is nice to know that the $ has a special position in
>> preg_matching,
>> > i kept this mail from a post from december in this list:
>> >
>> >  > such as $, you must escape it twice. For example:
>> >  >
>> >  > $matchme = "\$example";
>> >  > if (preg_match("/\$example/", $matchme)) {
>> >  >
>> >  > will not be matched because PHP interprets the \$ and passes it
as $.
>> >  > Instead, you must do this:
>> >  >
>> >  > if (preg_match("/\\\$example/", $matchme)) {
>> >
>>
>>

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



RE: [PHP] Re: Vars inside an sql query [Regular expression question]

2003-06-12 Thread Monu Ogbe
Ben, 

heredocs seem to do just what you are asking. 

http://www.onlamp.com/pub/a/php/2003/04/10/php_heredocs.html

If I can "include()" a file inside this construct, then it will 
solve my problem too :-?

Monu

-Original Message-----
From: Monu Ogbe 
Sent: 12 June 2003 14:12
To: [EMAIL PROTECTED]
Subject: RE: [PHP] Re: Vars inside an sql query [Regular expression
question]


Hi, 

I'll join the conversation, because I have a similar problem.  

PHP "interpolates" variable values in strings if these are enclosed in 
double quotes:

e.g., 

  $string = "select * FROM `table` where id='$value' order by name";

PHP does not interpolate variables contained in strings delimited by 
single quotes.  That much is clear.

What seems to happen in Ben's case is that strings retrieved from the 
database are treated as if they are delimited by single quotes.

I have the same trouble in the case of strings retrieved from a file.

I have not been able to find a function that FORCES the variables 
within a single-quoted string to be translated.

I am currently looking into "heredocs" because the heredoc construct, 
like double-quoted strings, does perform interpolation.

I'll report back if this works, but would love to hear if there is a
simpler solution.

Thanks, 

Monu

>Sorry this is more correct :
>
>-- starting query.php
>select * FROM `table` where id='$value' order by name
>-- ending query.php
>
>"Hatem Ben" <[EMAIL PROTECTED]> a écrit dans le message de news:
>[EMAIL PROTECTED]
>> Oh, ok this is how i want to do it exactly :
>>  query.php
>> > $query = "select * FROM `table` where id='$value' order by name";
>> ?>
>>
>>  parse.php
>> > $fcontents = join('' , file('query.php'));
>> preg_match_all("/^('\$(.*)')/si", $fcontents,$matches);
>> print_r($matches)
>> ?>
>>
>> Thanks
>>
>> "Chris Hayes" <[EMAIL PROTECTED]> a écrit dans le message de news:
>> [EMAIL PROTECTED]
>> > At 13:54 12-6-03, you wrote:
>> > >>I got a headache doing this, i need to get vars inside an sql
query.
>For
>> > >>example :
>> > >>
>> > >>$query = "select * FROM `table` where id='$value' order by name";
>> > >>preg_match_all("/^('\$(.*)')/si", $query,$matches);
>> >
>> >
>> > >That doesn't work as the new string already is like "select * FROM
>> `table`
>> > >where id='2' order by name" assuming $value was 2...
>> >
>> > True, so try using
>> >
>> > $query = "select * FROM `table` where id='__VALUE__' order by
name";
>> >
>> > if you insist on doing it this way.
>> >
>> > If you decide to keep trying with the $value, you need to know that
>> > variables inside "double quotes" are entered on the spot, while not
so
>> with
>> > 'single quotes'.
>> >
>> >
>> > Also it is nice to know that the $ has a special position in
>> preg_matching,
>> > i kept this mail from a post from december in this list:
>> >
>> >  > such as $, you must escape it twice. For example:
>> >  >
>> >  > $matchme = "\$example";
>> >  > if (preg_match("/\$example/", $matchme)) {
>> >  >
>> >  > will not be matched because PHP interprets the \$ and passes it
as $.
>> >  > Instead, you must do this:
>> >  >
>> >  > if (preg_match("/\\\$example/", $matchme)) {
>> >
>>
>>

-- 
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] Vars inside an sql query [Regular expression question] - Again

2003-06-12 Thread Monu Ogbe
Right then.  

Here's what I have done, and it works:

===Contents of query.txt===

===End Contents of query.txt===

Then:

===Contents of parse.php===

===End Contents of parse.php===

Now, whereas this works, I am still looking for a way to 
store and interpolate variables contained in "query.txt" 
without the kludge of having to embed the assignment of 
"$fcontents" inside the file as above :-(

Have fun, 

Monu

-Original Message-
From: Hatem Ben [mailto:[EMAIL PROTECTED]
Sent: 12 June 2003 14:59
To: [EMAIL PROTECTED]
Subject: [PHP] Vars inside an sql query [Regular expression question] -
Again


I'm asking again the same question, coz i guess my question wasn't
clear.

 i just need to retreive vars inside query.txt, my regular expression
seems to be correct for me, but i don't find why it doesn't wrk

-- Starting query.txt
select * FROM `table` where id='$value' order by name
-- Ending query.txt


-- Starting parse.php

- Ending parse.php


rewriting query is another question, that i agree also.

Thanks
Hatem

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



RE: [PHP] Easier way to delete all entries in an array?

2003-06-12 Thread Monu Ogbe
Or perhaps,

$the_array = array();

Monu

-Original Message-
From: Wendell Brown [mailto:[EMAIL PROTECTED]
Sent: 12 June 2003 16:31
To: James E Hicks III; [EMAIL PROTECTED]
Subject: Re: [PHP] Easier way to delete all entries in an array?


On Thu, 12 Jun 2003 10:13:10 -0400, James E Hicks III wrote:

>There's got to be an easier way, is there?
>
>for ($i=0; $i < count($the_array); $i++){
>   array_pop($the_array);
>}

Maybe this:

unset( $the_array );




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