[PHP] EREGI_REPLACE? HELP!!!
I'm trying to take a string and remove all invalid characters from it. $string=Frid#ays are@ re$ally G{}[]RE~AT. F*riday at 5 is be^tter.; The only characters that should be allowed are A-Z, a-z, 0-9, .(period), -(dash), ;(semi-colon), and :(colon). All other characters should be removed. After cleaning the string, the output should be: Fridays are really GREAT. Friday at 5 is better. Any ideas? Your help is appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] EREGI_REPLACE? HELP!!!
Kiason Turner mailto:[EMAIL PROTECTED] on Thursday, January 20, 2005 9:19 AM said: I'm trying to take a string and remove all invalid characters from it. $string=Frid#ays are@ re$ally G{}[]RE~AT. F*riday at 5 is be^tter.; Any ideas? Your help is appreciated. What have you tried so far? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EREGI_REPLACE? HELP!!!
On Thu, 20 Jan 2005 11:19:10 -0600, Kiason Turner [EMAIL PROTECTED] wrote: I'm trying to take a string and remove all invalid characters from it. $string=Frid#ays are@ re$ally G{}[]RE~AT. F*riday at 5 is be^tter.; The only characters that should be allowed are A-Z, a-z, 0-9, .(period), -(dash), ;(semi-colon), and :(colon). All other characters should be removed. After cleaning the string, the output should be: Fridays are really GREAT. Friday at 5 is better. Any ideas? Your help is appreciated. Maybe something like: $string = ereg_replace( [^-.:;[:alnum:][:space:]+], '', $string ); I'm no regex guru so there may be a better way.. but it seemed to work for me. -- Greg Donald Zend Certified Engineer http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] eregi_replace help needed
Hi, I want to locate patterns such as 12345678 1 23 45 67 89 1 2 34 567 890 and replace the pattern string with a new string. I tried $filter['message'] = eregi_replace([0-9\s]{4,},'string replaced', $filter['message']); but it does not work on all the above examples. Thanks for the assistance! Nico -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] eregi_replace help needed
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: January 29, 2004 8:53 AM To: [EMAIL PROTECTED] Subject: [PHP] eregi_replace help needed Hi, I want to locate patterns such as 12345678 1 23 45 67 89 1 2 34 567 890 and replace the pattern string with a new string. I tried $filter['message'] = eregi_replace([0-9\s]{4,},'string replaced', $filter['message']); but it does not work on all the above examples. Thanks for the assistance! Nico off the top of my head, I don't think '\s' is valid in a character class, so just use ' ' instead try eregi_replace([0-9 ]{4,} -Craig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] eregi_replace help needed
Hi, the off the top of your head was perfect. It is contrary to everything I've read on this, but it did the trick. off the top of my head, I don't think '\s' is valid in a character class, so just use ' ' instead try eregi_replace([0-9 ]{4,} -Craig Thanks Nico -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] eregi_replace help needed
Hi Nico, On 29 Jan 2004 at 17:52, [EMAIL PROTECTED] wrote: I want to locate patterns such as 12345678 1 23 45 67 89 1 2 34 567 890 and replace the pattern string with a new string. I tried $filter['message'] = eregi_replace([0-9\s]{4,},'string replaced', $filter['message']); Use preg_replace() with the i pattern modifier instead of eregi_replace(), e.g. preg_replace('/[\d\s]{4,}/i', 'string replaced', $string) Works like a charm. Cheers, Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] eregi_replace help
Hello all, I am trying to use php to read through an html file and replace all image paths, like such: Change images/firstimage.gif to http://www.blah.com/firstimage.gif; ... Change somesuch/images/secondimage.jpg to http://www.blah.com/secondimage.jpg; So I am going through the file and matching the image path strings, stripping them down to just the image name using basename, and then adding http://www.blah.com/; onto the beginning of them. Except it's not working, and I'm not sure where my logic has gone awry. Instead of replacing each image path with its respective image name, it is replacing all image paths with the *same* image name. Here is the code. (Yes I'm new, I apologize for the mess, there are a few lines in there I'm using for debugging purposes, to show me what it's doing.) ? $filename = newexample.html; $fd = fopen ($filename, r); $contents = fread ($fd, filesize ($filename)); while (preg_match('{()([A-z0-9_/-](\/))*[A-z0-9_/-]+(.gif|.jpg)}', $contents, $matches)) { echo bMATCHED:/b .$matches[0].br\n; $base = basename($matches[0]); $newimage = http://www.blah.com/.$base; echo brbase: .$base.br; echo new image: .$newimage.br; echo hr; $contents = eregi_replace('\/*[A-z0-9_/-]+(.gif|.jpg)', $newimage, $contents); print $contents; } fclose ($fd); ? When I run it, I get: ~ MATCHED: blah/images/first.gif base: first.gif new image: http://www.blah.com/first.gif Here it prints the contents of the html file, except all images look like http://www.blah.com/first.gif; (when there are supposed to be lots of other images, such as second.jpg, etc). ~ Where have I gone wrong? Thanks to all, as usual, for your hints and help. Jen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] eregi_replace help
BTW - I have found errors in the regular expression that I was matching so don't bother to point those out. ;) That shouldn't affect the nature of the problem I was asking about. --- Jennifer Swofford [EMAIL PROTECTED] wrote: Hello all, I am trying to use php to read through an html file and replace all image paths, like such: snip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] eregi_replace help
Jennifer-- A couple of things. eregi_replace does not have a limitation parameter, which means that if you use it *all* the strings that match your pattern will be replace with the new pattern. In your case, if I read your code correctly (and I may not--I'm doing this from memory), the eregi replacement you perform will change *all* the paths you have in your file, and not just the first one, which, I believe, is what you're looking for. Also, there shouldn't be any need to make the replacements one by one. A single replacement should be enough if all the original paths have to be transformed into the same URL. For example: ereg_replace ({/images/}{test.(jpg|gif)}, http://www.microsoft.com/images/\\2;, $t); This would replace any occurrence of /images/*.gif and /images/*.jpg to http://www.microsoft.com/images/*.gif; or *.jpg respectively (once again, double check my regex...doing this from memory). If you *do* need to change each occurrence individually, then you should use preg() instead, which uses Perl syntax and has a limitation parameter. Also--a minor thing and I'm sure you thought of it, but you're not saving the file at the end :-) Hope this helps. Cheers, Marco On Mon, 2002-10-07 at 20:01, Jennifer Swofford wrote: Hello all, I am trying to use php to read through an html file and replace all image paths, like such: Change images/firstimage.gif to http://www.blah.com/firstimage.gif; ... Change somesuch/images/secondimage.jpg to http://www.blah.com/secondimage.jpg; So I am going through the file and matching the image path strings, stripping them down to just the image name using basename, and then adding http://www.blah.com/; onto the beginning of them. Except it's not working, and I'm not sure where my logic has gone awry. Instead of replacing each image path with its respective image name, it is replacing all image paths with the *same* image name. Here is the code. (Yes I'm new, I apologize for the mess, there are a few lines in there I'm using for debugging purposes, to show me what it's doing.) ? $filename = newexample.html; $fd = fopen ($filename, r); $contents = fread ($fd, filesize ($filename)); while (preg_match('{()([A-z0-9_/-](\/))*[A-z0-9_/-]+(.gif|.jpg)}', $contents, $matches)) { echo bMATCHED:/b .$matches[0].br\n; $base = basename($matches[0]); $newimage = http://www.blah.com/.$base; echo brbase: .$base.br; echo new image: .$newimage.br; echo hr; $contents = eregi_replace('\/*[A-z0-9_/-]+(.gif|.jpg)', $newimage, $contents); print $contents; } fclose ($fd); ? When I run it, I get: ~ MATCHED: blah/images/first.gif base: first.gif new image: http://www.blah.com/first.gif Here it prints the contents of the html file, except all images look like http://www.blah.com/first.gif; (when there are supposed to be lots of other images, such as second.jpg, etc). ~ Where have I gone wrong? Thanks to all, as usual, for your hints and help. Jen -- 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] eregi_replace help
Thank you Marco! Between your post and the other stuff I happened to find at the same time, I got it working. Turned out I was making it much more difficult than it had to be. I ended up with: ? $filename = newexample.html; $fd = fopen ($filename, r); $contents = fread ($fd, filesize ($filename)); $contents = preg_replace(/(\)([A-z0-9]+(\/))*([A-z0-9]+)(\.)(jpg|gif)(\)/, \http://www.blah.com/$4.$6\;, $contents); echo $contents; fclose ($fd); ? Lo and behold, it works. Thanks all! Jen --- Marco Tabini [EMAIL PROTECTED] wrote: Jennifer-- A couple of things. eregi_replace does not have a limitation parameter, which means that if you use it *all* the strings that match your pattern will be replace with the new pattern. In your case, if I read your code correctly (and I may not--I'm doing this from memory), the eregi replacement you perform will change *all* the paths you have in your file, and not just the first one, which, I believe, is what you're looking for. Also, there shouldn't be any need to make the replacements one by one. A single replacement should be enough if all the original paths have to be transformed into the same URL. For example: ereg_replace ({/images/}{test.(jpg|gif)}, http://www.microsoft.com/images/\\2;, $t); This would replace any occurrence of /images/*.gif and /images/*.jpg to http://www.microsoft.com/images/*.gif; or *.jpg respectively (once again, double check my regex...doing this from memory). If you *do* need to change each occurrence individually, then you should use preg() instead, which uses Perl syntax and has a limitation parameter. Also--a minor thing and I'm sure you thought of it, but you're not saving the file at the end :-) Hope this helps. Cheers, Marco -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] eregi_replace HELP!!
Hello all! I would like to change all the links containing string microsite from $contenido1 to: a href=http://www.whatever.com;Link not available/a. The rest of the links of $contenido1 would have to be ontouched. To do this, I tried $contenido1=eregi_replace((a href=.*microsite.*/a),a href=\http://www.whatever.com\;Link not available/a,$contenido1); It changes links with microsite in it but erases the ones without microsite. How can I make this work? TIA Regards -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] eregi_replace help!
Hi, I have a rather annoying eregi_replace which I can't get to work. I have a string, $page which contains a webpage. In the page links are denoted like so: ###LINK###Link Name###URL or Section###ELINK### There are a number of these in $page. I need to use eregi_replace() to replace the above string with a proper link: a href=URL or SectionLink Name/a Not too bad, right? However, If need to do some manipulation on the URL or Section bit. If it is a URL (begining with http://;, ftp://;, etc) then it just needs to be put there, ie: ###LINK###PHP###http://www.php.net/###ELINK### = a href=http://www.php.net;PHP/a But if it is a section on the site like this: ###LINK###Hello###Main.Section 1.Section 2.Hello World###ELINK### It need to be replaced with this: a href=/main.section_1.section_2.hello_world.phpHello/a Here is the rather long (an not working) eregi_replace call I have: $page = eregi_replace(###LINK##(.*)(.*)###ELINK###, a href=\.(eregi(^http://;, \\2) ? trim(\\2) : (strtolower(str_replace(\\, _, eregi_replace((/| |:|\*|\?|||\|),_,trim(\\2..php)).\\1/a, $page); 1. I dont think the regular express is really right 2. I'm getting the message Warning: Unexpected character in input: '\' (ASCII=92) state=1 in c:\users\david\help\www\generate.php on line 24 serval times, which is the above line. Any ideas on how to make this work would be great! Thanks! Regards, David -- 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]