| parsing PHP in single quotes
|
Scally_Ally

msg:3504472 | 9:45 am on Nov 14, 2007 (gmt 0) | 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

msg:3504476 | 10:13 am on Nov 14, 2007 (gmt 0) | 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

msg:3504482 | 10:25 am on Nov 14, 2007 (gmt 0) | 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

msg:3504496 | 10:42 am on Nov 14, 2007 (gmt 0) | :) 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

msg:3504519 | 11:28 am on Nov 14, 2007 (gmt 0) | yeah, that would work. can then just do sitewide find and replace on the function name. Brilliant Thanks Ally
|
|
|