This is a discussion on How do i replace table names? within the PHP General forums, part of the PHP Programming Forums category; I want to replace something like this: $sql = "CREATE TABLE bas_table ( )"; With this: "CREATE TABLE hugo_table ( )"; ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Bas wrote:
> I want to replace something like this: > > $sql = "CREATE TABLE bas_table ( > )"; > > With this: > > "CREATE TABLE hugo_table ( > )"; > > And do the same for INSERT INTO... How do i do this? If you know that "bas_" will not appear within your data, then a simple str_replace() will do. $new_data = str_replace('bas_','dummy_',$old_data); If you're not sure, then a regular expression or more inclusive str_replace() would be necessary. $new_data = str_replace('CREATE TABLE bas','CREATE TABLE dummy',$old_data); or $new_data = preg_replace('^CREATE TABLE bas','CREATE TABLE dummy',$old_data); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com |