Re: Re[2]: [PHP] ereg_replace help
On 18 Mar 2004 Richard Davey wrote: > Nope, because in the only reference book I had to hand it said the ^ > matched the start of a string so it didn't occur to me to try it. > > Thanks to John I now know when used in a block it's no longer limited > to the start of the string. The code you posted above works, thanks. The '^' has a totally different meaning inside a character class than its meaning outside the class. It's not a amtter of it being "limited" so much as just "different" (actually I guess "overloaded" is the real term). -- Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] ereg_replace help
Hello Chris, Thursday, March 18, 2004, 3:28:01 PM, you wrote: CH> did you try CH> $output = ereg_replace('[^[:alnum:]]', '', $string); CH> ? Nope, because in the only reference book I had to hand it said the ^ matched the start of a string so it didn't occur to me to try it. Thanks to John I now know when used in a block it's no longer limited to the start of the string. The code you posted above works, thanks. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
At 16:21 18-3-04, you wrote: I can do the reverse with: $output = ereg_replace('[[:alnum:]]', '', $string); Which will happily remove all alpha-numeric characters from $string! But I want it to remove anything but.. suggestions please? did you try $output = ereg_replace('[^[:alnum:]]', '', $string); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
From: "Richard Davey" <[EMAIL PROTECTED]> > I'm sure this is blindingly simple, but could anyone tell me how to > get an ereg_replace() to return a string where all characters OTHER > than alpha-numerics have been stripped out? $output = ereg_replace('[^a-zA-Z0-9]','',$string); The ^ is NOT (when the first character in a bracketed character set). So anything NOT alphanumeric is replaced. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ereg_replace help
Hi all, I'm sure this is blindingly simple, but could anyone tell me how to get an ereg_replace() to return a string where all characters OTHER than alpha-numerics have been stripped out? I can do the reverse with: $output = ereg_replace('[[:alnum:]]', '', $string); Which will happily remove all alpha-numeric characters from $string! But I want it to remove anything but.. suggestions please? -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ereg_replace help
> * Thus wrote Martin Towell ([EMAIL PROTECTED]): > > Hi All, > > > > I have an array of strings in the following format: > > "abcd - rst" > > "abcd - uvw" > > "abcd - xyz" > > "foobar - rst" > > "blah - rst" > > "googol - uvw" > > > > What I want to do is strip everything from the " - " bit of > the string to > > the end, _but_ only for the strings that don't start with "abcd" > > > > I was thinking something like the following: > > echo ereg_replace("(!abcd) - xyz", "\\1", $str)."\n"; > > but obviously this doesn't work, otherwise I wouldn't be > emailing the > > list... > > > > $newarray = preg_replace('/((? > > Can anyone help? I need to use ereg_replace() because it's > part of our code > > library and therefore can't change :( > > How do you mean its part of your code library? I would strongly > suggest using preg_* for its speed and capabilites. > > Curt thanks for everyone's help... > How do you mean its part of your code library? I mean that the function I'm having to call is passed an array (coming from a databse) and it has an option to do an ereg_replace() on the incoming array. Due to the amount of other code relying on it, is very hard to change without causing something strange to happen elsewhere :( If all the code was mine, then I wouldn't have any reservations on changing it in an instant. I'm having to improve the code gradually (good luck to me) Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
* Thus wrote Martin Towell ([EMAIL PROTECTED]): > Hi All, > > I have an array of strings in the following format: > "abcd - rst" > "abcd - uvw" > "abcd - xyz" > "foobar - rst" > "blah - rst" > "googol - uvw" > > What I want to do is strip everything from the " - " bit of the string to > the end, _but_ only for the strings that don't start with "abcd" > > I was thinking something like the following: > echo ereg_replace("(!abcd) - xyz", "\\1", $str)."\n"; > but obviously this doesn't work, otherwise I wouldn't be emailing the > list... > $newarray = preg_replace('/((? Can anyone help? I need to use ereg_replace() because it's part of our code > library and therefore can't change :( How do you mean its part of your code library? I would strongly suggest using preg_* for its speed and capabilites. Curt -- "My PHP key is worn out" PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
On Tue, 2003-11-18 at 02:30, Jason Wong wrote: > On Tuesday 18 November 2003 13:37, Martin Towell wrote: > > > I have an array of strings in the following format: > > "abcd - rst" > > "abcd - uvw" > > "abcd - xyz" > > "foobar - rst" > > "blah - rst" > > "googol - uvw" > > > > What I want to do is strip everything from the " - " bit of the string to > > the end, _but_ only for the strings that don't start with "abcd" > > > > I was thinking something like the following: > > echo ereg_replace("(!abcd) - xyz", "\\1", $str)."\n"; > > but obviously this doesn't work, otherwise I wouldn't be emailing the > > list... > > > > Can anyone help? I need to use ereg_replace() because it's part of our code > > library and therefore can't change :( > > May be quicker (definitely easier) to explode() on ' - '. The following is untested: --- foreach( $myArray as $id => $entry ) { if( ($pos = strpos( 'abcd' ) !== false && $pos === 0 ) { $parts = explode( ' - ', $entry ); $myArray[$id] = $parts[0]; } } print_r( $myArray ); --- Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
On Monday 17 November 2003 23:37, Martin Towell <[EMAIL PROTECTED]> sent a missive stating: > Hi All, > > I have an array of strings in the following format: > "abcd - rst" > "abcd - uvw" > "abcd - xyz" > "foobar - rst" > "blah - rst" > "googol - uvw" > > What I want to do is strip everything from the " - " bit of the string to > the end, _but_ only for the strings that don't start with "abcd" > > I was thinking something like the following: > echo ereg_replace("(!abcd) - xyz", "\\1", $str)."\n"; > but obviously this doesn't work, otherwise I wouldn't be emailing the > list... > > Can anyone help? I need to use ereg_replace() because it's part of our code > library and therefore can't change :( > > TIA > Martin Possibly have to do a if statement, ereg for the abcd and then if ture, do your ereg replace? I can't logically think how that would work in one regex, since you want to match first and then replace...but my regex skills aren't top notch either :) Henrik -- Henrik Hudson [EMAIL PROTECTED] "`If there's anything more important than my ego around, I want it caught and shot now.'" --Hitchhikers Guide to the Galaxy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
On Tuesday 18 November 2003 13:37, Martin Towell wrote: > I have an array of strings in the following format: > "abcd - rst" > "abcd - uvw" > "abcd - xyz" > "foobar - rst" > "blah - rst" > "googol - uvw" > > What I want to do is strip everything from the " - " bit of the string to > the end, _but_ only for the strings that don't start with "abcd" > > I was thinking something like the following: > echo ereg_replace("(!abcd) - xyz", "\\1", $str)."\n"; > but obviously this doesn't work, otherwise I wouldn't be emailing the > list... > > Can anyone help? I need to use ereg_replace() because it's part of our code > library and therefore can't change :( May be quicker (definitely easier) to explode() on ' - '. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The giraffe you thought you offended last week is willing to be nuzzled today. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
On Tue, Nov 18, 2003 at 04:37:52PM +1100, Martin Towell wrote: : : I have an array of strings in the following format: : "abcd - rst" : "abcd - uvw" : "abcd - xyz" : "foobar - rst" : "blah - rst" : "googol - uvw" : : What I want to do is strip everything from the " - " bit of the string to : the end, _but_ only for the strings that don't start with "abcd" : : I was thinking something like the following: : echo ereg_replace("(!abcd) - xyz", "\\1", $str)."\n"; : but obviously this doesn't work, otherwise I wouldn't be emailing the : list... You can't use "!" because it's not a valid special character in regular expressions. It's really hard to craft do-not-match-this-word patterns. You're better off separating the two pieces of logic. $arr = array( "abcd - rst", "abcd - uvw", "abcd - xyz", "foobar - rst", "blah - rst", "googol - uvw" ); reset($arr); while (list($key, $value) = each($arr)) { if (substr($value, 0, 5) != 'abcd ') { $arr[$key] = ereg_replace('^(.*) - .*$', '\1', $value); } } print_r($arr); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ereg_replace help
Hi All, I have an array of strings in the following format: "abcd - rst" "abcd - uvw" "abcd - xyz" "foobar - rst" "blah - rst" "googol - uvw" What I want to do is strip everything from the " - " bit of the string to the end, _but_ only for the strings that don't start with "abcd" I was thinking something like the following: echo ereg_replace("(!abcd) - xyz", "\\1", $str)."\n"; but obviously this doesn't work, otherwise I wouldn't be emailing the list... Can anyone help? I need to use ereg_replace() because it's part of our code library and therefore can't change :( TIA Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ereg_replace Help
Hi all, I have a large file that I am trying to parse. I have a many lines that look like this \\text1 I need an expression that will change \\text1 to text1= so if I have something like this \\text1 asdfkjaslkfj asdlfkjasljkf asdlkfjasldfkj asldkfjalskfj \\text2 erweiurwoeir werqwer qwer qwerqw er \\text3 asdlfkw xcvsdf zxcvcgn sdfgwr xcdfvszdfg it will become text1 = " asdfkjaslkfj asdlfkjasljkf asdlkfjasldfkj asldkfjalskfj " text2 = erweiurwoeir werqwer qwer qwerqw er " text3 = "asdlfkw xcvsdf zxcvcgn sdfgwr xcdfvszdfg " Any Ideas, Michael -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ereg_replace help
On Sun, 2002-02-03 at 21:34, Martin Towell wrote: > is that a direct copy from your code? - if it is, there's two errors > 1. you have a comma just before the closing backet > 2. the function is : implode(string glue, array pieces) >so that would be : $content = implode("\n", $lines); >ie. the two arguments are the wrong way around > Martin Actually, implode() will take its arguments in either order, so there's really only one thing (the comma) which could be causing the problem. Also, for the original poster: if you only need to do simple string replacements, you should see whether str_replace() will serve your purpose. It's much less expensive than ereg_replace(). If you feel that you require regular expressions, the preg_*() functions are less expensive than the ereg_*() equivalents. Torben > -Original Message- > From: John P. Donaldson [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 04, 2002 4:32 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] ereg_replace help > > > I'm not actually replacing \n with , I just used > that as an example. When I tried Martin's solution, I > got a parse error on this line: > > $content = implode($lines, "\n",); > > I checked the manual and it's constructed properly .. > I think. What could be giving me the parse error on > this line. The previous line reads: > > $lines = file("log.txt"); > > Thanks, > John > > > > > --- Mike Frazer <[EMAIL PROTECTED]> wrote: > > nl2br() would serve that purpose as well. See the > > Strings section of the > > Functions Reference in the manual. > > > > Mike Frazer > > > > > > > > "Martin Towell" <[EMAIL PROTECTED]> wrote in > > message > > > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > > $lines = file("filename_here.blah"); // read in > > file as an array > > > $content = implode("\n", $lines); // join it > > all back together > > > $new_cont = ereg_replace("from", "to", $content); > > > fopen(...); fputs(..., $new_content); > > fclose(...); > > > > > > > > > if your intent is to replace all new lines with > > 's then use this > > instead > > > ... > > > > > > $lines = file("filename_here.blah"); // read in > > file as an array > > > $content = implode("", $lines); // join it > > all back together > > > fopen(...); fputs(..., $content); fclose(...); > > > > > > > > > hope this helps > > > > > > -Original Message- > > > From: John P. Donaldson > > [mailto:[EMAIL PROTECTED]] > > > Sent: Monday, February 04, 2002 3:39 PM > > > To: php > > > Subject: [PHP] ereg_replace help > > > > > > > > > I have a file open and can successfully write to > > it, > > > but I was to be able to search for a certain > > string of > > > text and replace it with a string of text. I > > can't > > > figure out how to construct a proper ereg_replace > > > statement to search through this file and do the > > > replacing. Examples I've seen are in the manner > > of: > > > > > > $text = "line1\nline2\n"; > > > fputs(ereg_replace("\n", "", $text)); > > > > > > But how do I set the value of $text to be the > > entire > > > contents of the text file I've got open so it can > > > search through the entire file to find matches and > > > replace those matches? Any help is greatly > > > appreciated. > > > > > > Thanks, > > > John > > > > > > __ > > > Do You Yahoo!? > > > Great stuff seeking new owners in Yahoo! Auctions! > > > http://auctions.yahoo.com > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: > > http://www.php.net/unsub.php > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > __ > Do You Yahoo!? > Great stuff seeking new owners in Yahoo! Auctions! > http://auctions.yahoo.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
On Monday 04 February 2002 13:31, John P. Donaldson wrote: > I'm not actually replacing \n with , I just used > that as an example. When I tried Martin's solution, I > got a parse error on this line: > > $content = implode($lines, "\n",); You've got a trailing comma. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* A halted retreat Is nerve-wracking and dangerous. To retain people as men -- and maidservants Brings good fortune. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ereg_replace help
is that a direct copy from your code? - if it is, there's two errors 1. you have a comma just before the closing backet 2. the function is : implode(string glue, array pieces) so that would be : $content = implode("\n", $lines); ie. the two arguments are the wrong way around Martin -Original Message- From: John P. Donaldson [mailto:[EMAIL PROTECTED]] Sent: Monday, February 04, 2002 4:32 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] ereg_replace help I'm not actually replacing \n with , I just used that as an example. When I tried Martin's solution, I got a parse error on this line: $content = implode($lines, "\n",); I checked the manual and it's constructed properly .. I think. What could be giving me the parse error on this line. The previous line reads: $lines = file("log.txt"); Thanks, John --- Mike Frazer <[EMAIL PROTECTED]> wrote: > nl2br() would serve that purpose as well. See the > Strings section of the > Functions Reference in the manual. > > Mike Frazer > > > > "Martin Towell" <[EMAIL PROTECTED]> wrote in > message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > $lines = file("filename_here.blah"); // read in > file as an array > > $content = implode("\n", $lines); // join it > all back together > > $new_cont = ereg_replace("from", "to", $content); > > fopen(...); fputs(..., $new_content); > fclose(...); > > > > > > if your intent is to replace all new lines with > 's then use this > instead > > ... > > > > $lines = file("filename_here.blah"); // read in > file as an array > > $content = implode("", $lines); // join it > all back together > > fopen(...); fputs(..., $content); fclose(...); > > > > > > hope this helps > > > > -Original Message- > > From: John P. Donaldson > [mailto:[EMAIL PROTECTED]] > > Sent: Monday, February 04, 2002 3:39 PM > > To: php > > Subject: [PHP] ereg_replace help > > > > > > I have a file open and can successfully write to > it, > > but I was to be able to search for a certain > string of > > text and replace it with a string of text. I > can't > > figure out how to construct a proper ereg_replace > > statement to search through this file and do the > > replacing. Examples I've seen are in the manner > of: > > > > $text = "line1\nline2\n"; > > fputs(ereg_replace("\n", "", $text)); > > > > But how do I set the value of $text to be the > entire > > contents of the text file I've got open so it can > > search through the entire file to find matches and > > replace those matches? Any help is greatly > > appreciated. > > > > Thanks, > > John > > > > __ > > Do You Yahoo!? > > Great stuff seeking new owners in Yahoo! Auctions! > > http://auctions.yahoo.com > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: > http://www.php.net/unsub.php > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > __ Do You Yahoo!? Great stuff seeking new owners in Yahoo! Auctions! http://auctions.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
I'm not actually replacing \n with , I just used that as an example. When I tried Martin's solution, I got a parse error on this line: $content = implode($lines, "\n",); I checked the manual and it's constructed properly .. I think. What could be giving me the parse error on this line. The previous line reads: $lines = file("log.txt"); Thanks, John --- Mike Frazer <[EMAIL PROTECTED]> wrote: > nl2br() would serve that purpose as well. See the > Strings section of the > Functions Reference in the manual. > > Mike Frazer > > > > "Martin Towell" <[EMAIL PROTECTED]> wrote in > message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > $lines = file("filename_here.blah"); // read in > file as an array > > $content = implode("\n", $lines); // join it > all back together > > $new_cont = ereg_replace("from", "to", $content); > > fopen(...); fputs(..., $new_content); > fclose(...); > > > > > > if your intent is to replace all new lines with > 's then use this > instead > > ... > > > > $lines = file("filename_here.blah"); // read in > file as an array > > $content = implode("", $lines); // join it > all back together > > fopen(...); fputs(..., $content); fclose(...); > > > > > > hope this helps > > > > -Original Message- > > From: John P. Donaldson > [mailto:[EMAIL PROTECTED]] > > Sent: Monday, February 04, 2002 3:39 PM > > To: php > > Subject: [PHP] ereg_replace help > > > > > > I have a file open and can successfully write to > it, > > but I was to be able to search for a certain > string of > > text and replace it with a string of text. I > can't > > figure out how to construct a proper ereg_replace > > statement to search through this file and do the > > replacing. Examples I've seen are in the manner > of: > > > > $text = "line1\nline2\n"; > > fputs(ereg_replace("\n", "", $text)); > > > > But how do I set the value of $text to be the > entire > > contents of the text file I've got open so it can > > search through the entire file to find matches and > > replace those matches? Any help is greatly > > appreciated. > > > > Thanks, > > John > > > > __ > > Do You Yahoo!? > > Great stuff seeking new owners in Yahoo! Auctions! > > http://auctions.yahoo.com > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: > http://www.php.net/unsub.php > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > __ Do You Yahoo!? Great stuff seeking new owners in Yahoo! Auctions! http://auctions.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace help
nl2br() would serve that purpose as well. See the Strings section of the Functions Reference in the manual. Mike Frazer "Martin Towell" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > $lines = file("filename_here.blah"); // read in file as an array > $content = implode("\n", $lines); // join it all back together > $new_cont = ereg_replace("from", "to", $content); > fopen(...); fputs(..., $new_content); fclose(...); > > > if your intent is to replace all new lines with 's then use this instead > ... > > $lines = file("filename_here.blah"); // read in file as an array > $content = implode("", $lines); // join it all back together > fopen(...); fputs(..., $content); fclose(...); > > > hope this helps > > -Original Message- > From: John P. Donaldson [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 04, 2002 3:39 PM > To: php > Subject: [PHP] ereg_replace help > > > I have a file open and can successfully write to it, > but I was to be able to search for a certain string of > text and replace it with a string of text. I can't > figure out how to construct a proper ereg_replace > statement to search through this file and do the > replacing. Examples I've seen are in the manner of: > > $text = "line1\nline2\n"; > fputs(ereg_replace("\n", "", $text)); > > But how do I set the value of $text to be the entire > contents of the text file I've got open so it can > search through the entire file to find matches and > replace those matches? Any help is greatly > appreciated. > > Thanks, > John > > __ > Do You Yahoo!? > Great stuff seeking new owners in Yahoo! Auctions! > http://auctions.yahoo.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ereg_replace help
$lines = file("filename_here.blah"); // read in file as an array $content = implode("\n", $lines); // join it all back together $new_cont = ereg_replace("from", "to", $content); fopen(...); fputs(..., $new_content); fclose(...); if your intent is to replace all new lines with 's then use this instead ... $lines = file("filename_here.blah"); // read in file as an array $content = implode("", $lines); // join it all back together fopen(...); fputs(..., $content); fclose(...); hope this helps -Original Message- From: John P. Donaldson [mailto:[EMAIL PROTECTED]] Sent: Monday, February 04, 2002 3:39 PM To: php Subject: [PHP] ereg_replace help I have a file open and can successfully write to it, but I was to be able to search for a certain string of text and replace it with a string of text. I can't figure out how to construct a proper ereg_replace statement to search through this file and do the replacing. Examples I've seen are in the manner of: $text = "line1\nline2\n"; fputs(ereg_replace("\n", "", $text)); But how do I set the value of $text to be the entire contents of the text file I've got open so it can search through the entire file to find matches and replace those matches? Any help is greatly appreciated. Thanks, John __ Do You Yahoo!? Great stuff seeking new owners in Yahoo! Auctions! http://auctions.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ereg_replace help
I have a file open and can successfully write to it, but I was to be able to search for a certain string of text and replace it with a string of text. I can't figure out how to construct a proper ereg_replace statement to search through this file and do the replacing. Examples I've seen are in the manner of: $text = "line1\nline2\n"; fputs(ereg_replace("\n", "", $text)); But how do I set the value of $text to be the entire contents of the text file I've got open so it can search through the entire file to find matches and replace those matches? Any help is greatly appreciated. Thanks, John __ Do You Yahoo!? Great stuff seeking new owners in Yahoo! Auctions! http://auctions.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ereg_replace: Help!
This works: $str = ''; echo eregi_replace("", "Replaced", $str); -- Plutarck Should be working on something... ...but forgot what it was. "Erica Douglass" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I have one ereg_replace problem that I cannot seem to fix. > > I need to delete an IMG tag. The only thing I know about this tag is that > it will contain > > SRC="images/headers > > in the string. Here is an example: > > > > I tried this, but it didn't work: > > $contents = ereg_replace ("", "", $contents); > > Can someone please help? > > Thanks, > Erica > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] ereg_replace: Help!
I have one ereg_replace problem that I cannot seem to fix. I need to delete an IMG tag. The only thing I know about this tag is that it will contain SRC="images/headers in the string. Here is an example: I tried this, but it didn't work: $contents = ereg_replace ("", "", $contents); Can someone please help? Thanks, Erica -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]