Jump to content


Photo

simple ereg_replace help


  • Please log in to reply
7 replies to this topic

#1 belick

belick
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 11 July 2006 - 03:45 AM

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);

<?="C"+"Y"+"T"+"N"+"E"+"T"+"."+"C"+"O"+"M";?>
Cytnet.com :-)

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 11 July 2006 - 03:54 AM

str_replace is not regex. Try this with preg_replace: /^dbo\.Table\d+\./
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 11 July 2006 - 03:51 PM

<?
$string="dbo.Table1.Field1";

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

echo $a;
?>

result

Field1
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 11 July 2006 - 04:37 PM

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
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 11 July 2006 - 04:54 PM

Also this way mate all throw all the table ok.


This is not as efficient or modular.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#6 belick

belick
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 12 July 2006 - 03:31 PM

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
<?="C"+"Y"+"T"+"N"+"E"+"T"+"."+"C"+"O"+"M";?>
Cytnet.com :-)

#7 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 12 July 2006 - 04:18 PM

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


If it always starts with "dbo": /^dbo\.[^.]+\./
If you want to remove everything before the last period: /^.+\./
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#8 belick

belick
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 July 2006 - 10:39 PM

like always, effigy, you are the best!!!!
<?="C"+"Y"+"T"+"N"+"E"+"T"+"."+"C"+"O"+"M";?>
Cytnet.com :-)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users