Welcome to WebmasterWorld Guest from 54.227.110.209

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

parsing PHP in single quotes

     

Scally_Ally

9:45 am on Nov 14, 2007 (gmt 0)

5+ Year Member



Hello,
was wondering if anybody knows if there is a php.ini setting for parsing single quotes strings?
eg.

$my_var = "world";
echo 'hello $my_var';

My next question after that is. Is there any way to globally define a variable and use it in a string, eg.

define("MY_VAR", "world");
echo 'hello {MY_VAR}';

Any help appreciated.
Thanks
Ally

vincevincevince

10:13 am on Nov 14, 2007 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member



No, you cannot parse PHP within single quotes, you need to get out of them again:

$my_var = "world";
echo 'hello $my_var!';

Becomes:

$my_var = "world";
echo 'hello '.$my_var.'!';

Why do you want to parse PHP within single quotes?

Your define() syntax seems fine, although you are defining constants not variables, and you can't get them from within quotes. Just use a standard variable and then use the 'global' keyword.

Scally_Ally

10:25 am on Nov 14, 2007 (gmt 0)

5+ Year Member



thanks vince,
i am modifying an out of the box ecommerce site to become 3 sites in 1.

now i have duplicated all the tables in the db like so:
table_name
becomes
table_name1, table_name2, table_name3
or
$my_var = 1;
table_name$my_var

I want to do a global find and replace to change any reference to these table name, to save using global $my_var; in every function i want to use a constant.
On top of this alot of the SQL statements are written using single quotes and not doubles so i would need to parse single quotes.

Its a wierd one i know but i really would like not to have to go through every script and manually alter the SQL statements to accomodate what i have done.

Thanks
Ally

[edited by: Scally_Ally at 10:26 am (utc) on Nov. 14, 2007]

vincevincevince

10:42 am on Nov 14, 2007 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member



:) Change your mysql_query() function.

function mysql_fake_query($string)
{
.... do any changes needed here ....
e.g. $string=str_replace('$name',$name,$string);
return mysql_query($string);
}

Scally_Ally

11:28 am on Nov 14, 2007 (gmt 0)

5+ Year Member



yeah, that would work.
can then just do sitewide find and replace on the function name.
Brilliant

Thanks
Ally

 

Featured Threads

Hot Threads This Week

Hot Threads This Month