Jump to content

Archived

This topic is now archived and is closed to further replies.

belick

simple ereg_replace help

Recommended Posts

I need to take out anything that start with dbo.Table1. for example:

dbo.Table1.Field1
dbo.Table2.Field2
dbo.Table2.Field2
dbo.Table3.Field3

need to be:
Field1
Field2
Field2
Field3

$s = str_replace("dbo.(.*).", "", $string);

Share this post


Link to post
Share on other sites
str_replace is not regex. Try this with preg_replace: /^dbo\.Table\d+\./

Share this post


Link to post
Share on other sites
<?
$string="dbo.Table1.Field1";

$a=eregi_replace("dbo.Table1.", "", $string);

echo $a;
?>

result

Field1

Share this post


Link to post
Share on other sites
Also this way mate all throw all the table ok.


<?
//just chage $b=explode("",tablename);

$b=array("dbo.Table1.Field1"
,"dbo.Table2.Field2"
,"dbo.Table3.Field3"
,"dbo.Table4.Field4");

while(list($k,$v)=each($b)) {

$x=substr($v, 11);

echo "<br>$x";
}


?>

//out come

Field1
Field2
Field3
Field4

Share this post


Link to post
Share on other sites
[quote author=redarrow link=topic=100147.msg395258#msg395258 date=1152635864]
Also this way mate all throw all the table ok.
[/quote]

This is not as efficient or modular.

Share this post


Link to post
Share on other sites
right, but the string is not somthing with "table" only it can be "dbo.(*.*).Field3".

$string = 'dbo.Table3.Field3';
$pattern = '/^dbo\.Table\d+\./';
$replacement = '';
echo preg_replace($pattern, $replacement, $string);

bottom line, I need to get rid of anything before the field name.

Thanks

Share this post


Link to post
Share on other sites
[quote author=belick link=topic=100147.msg395778#msg395778 date=1152718288]
bottom line, I need to get rid of anything before the field name.
[/quote]

If it always starts with "dbo": /^dbo\.[^.]+\./
If you want to remove everything before the last period: /^.+\./

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.