How do i replace table names?

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 ( )"; ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-03-2003
Bas
 
Posts: n/a
Default How do i replace table names?

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?

Regards,

Bas
Reply With Quote
  #2 (permalink)  
Old 11-03-2003
John W. Holmes
 
Posts: n/a
Default Re: [PHP] How do i replace table names?

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:55 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0