homepage Welcome to WebmasterWorld Guest from 54.204.94.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
parsing PHP in single quotes
Scally_Ally

5+ Year Member



 
Msg#: 3504470 posted 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

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



 
Msg#: 3504470 posted 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

5+ Year Member



 
Msg#: 3504470 posted 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

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



 
Msg#: 3504470 posted 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

5+ Year Member



 
Msg#: 3504470 posted 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved