Re: [PHP] String Manipulation
Rodrigo de Oliveira Costa wrote: Hi guys I have the following intention and would really like to know if tis possible and if its possible how should it be done. I have a string that is something like this: "1. Prologue2. First days3. Drastic choice4. Sowarocs5. Training6. Teneb" How can I retrieve the Values and assign it to a variable, and next retrieve the name and assign it to another variable and so on... Didn't you ask this a few days ago? I gave you an answer: http://marc.theaimsgroup.com/?l=php-general&m=114923129030154&w=2 -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String manipulation out of the box solution?
Richard Lynch wrote: On Tue, May 10, 2005 5:58 am, Merlin said: I am writing an internal full text search engine and do have trouble in outputting the text in an apropriate way. Problem is that if there is more than one word I cant handle the text cropping. For example: Search term: php germany Text from database: There is no such great language than php. Amongh those countries using this language is Germany with a good percentage of users. Text output should be: ...language than php. Amongh... language is Germay with a good... Similar to the way google does it. I tried it now with a couple of ways but failed for most (I tried with strpos and substr). Is there a solution out of the box with php, or maybe anybody knows a good script which does that. This does sound like a standard feature to me. Here's a quickie, untested, and probably with some kind of logic errors, or at least things not quite what you want. $fulltext = "There is no such great language than php. Amongh those countries using this language is Germany with a good percentage of users."; $words = explode(" ", "php germany"); $snippets = ''; while (list(, $word) = each($words)){ if (!stristr($snippets, $word)){ //skip this if we already got the word. $start = strpos($fulltext, $word); if ($start !== false){ $end = $start + strlen($word); $jumpback = strpos(' ', $fulltext, $start - 20); $jumpforward = strpos(' ', $fulltext, $end + 20); $snippet = substr($fulltext, $jumpback, $jumpforward); $snippets .= " $snippet "; } } } reset($words); while (, $word) = each($words)){ $snippets = str_replacei($word, "$word", $snippets); } echo $snippets; To Do: Might wanna store an array of start/end numbers for snippets, then sort by start, then combine those that "overlap" one end to the next start, *THEN* combine those snippets, so you don't have snippets out or order, nor overlapping. Still, I got ya started... Hi Richard, thank you for the jump start! I have fixed some errors within the script and now it works ( I am attaching the script). You are right, the overlap is a to do. Best regards, Merlin $fulltext = "There is no such great language than php. Amongh those countries using this language is Germany with a good percentage of users."; $words = explode(" ", "php Germany"); $snippets = ''; while (list(, $word) = each($words)){ if (!stristr($snippets, $word)){ //skip this if we already got the word. $start = strpos($fulltext, $word); if ($start !== false){ $end = $start + strlen($word); $jumpback = strpos($fulltext, ' ',$start - 20); $jumpforward = strpos( $fulltext,' ', $end + 20); $snippet = '...'.substr($fulltext, $jumpback, $jumpforward).'...'; $snippets .= " $snippet "; } } } reset($words); while (list(, $word) = each($words)){ $snippets = str_replace($word, "$word", $snippets); } echo $snippets; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String manipulation out of the box solution?
On Tue, May 10, 2005 5:58 am, Merlin said: > I am writing an internal full text search engine and do have trouble in > outputting the text in an apropriate way. > > Problem is that if there is more than one word I cant handle the text > cropping. > > For example: > Search term: php germany > Text from database: There is no such great language than php. Amongh those > countries using this language is Germany with a good percentage of users. > Text output should be: > ...language than php. Amongh... language is Germay with a good... > > Similar to the way google does it. I tried it now with a couple of ways > but > failed for most (I tried with strpos and substr). > > Is there a solution out of the box with php, or maybe anybody knows a good > script which does that. This does sound like a standard feature to me. Here's a quickie, untested, and probably with some kind of logic errors, or at least things not quite what you want. $fulltext = "There is no such great language than php. Amongh those countries using this language is Germany with a good percentage of users."; $words = explode(" ", "php germany"); $snippets = ''; while (list(, $word) = each($words)){ if (!stristr($snippets, $word)){ //skip this if we already got the word. $start = strpos($fulltext, $word); if ($start !== false){ $end = $start + strlen($word); $jumpback = strpos(' ', $fulltext, $start - 20); $jumpforward = strpos(' ', $fulltext, $end + 20); $snippet = substr($fulltext, $jumpback, $jumpforward); $snippets .= " $snippet "; } } } reset($words); while (, $word) = each($words)){ $snippets = str_replacei($word, "$word", $snippets); } echo $snippets; To Do: Might wanna store an array of start/end numbers for snippets, then sort by start, then combine those that "overlap" one end to the next start, *THEN* combine those snippets, so you don't have snippets out or order, nor overlapping. Still, I got ya started... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string manipulation
Jason Wong wrote: str_pad(), please RTFM before you ask such questions. It's obvious from your subject that you know it's something to do with strings, so where better than to look at the chapter on String Functions? Browse through them, checkout the examples, it's a good way to learn. But I searched the manual for strings, and all I got was results for threads. ;) -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string manipulation
On Friday 13 August 2004 01:00, Matthew Oatham wrote: > Hi I am trying to track down a method for transferring a database id such > as 5 into a nice formatted order id such as ORD0005 - where the format for > the order id is "ORD" + 5 digits made up of the database id str_pad(), please RTFM before you ask such questions. It's obvious from your subject that you know it's something to do with strings, so where better than to look at the chapter on String Functions? Browse through them, checkout the examples, it's a good way to learn. -- 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 -- /* Ginsburg's Law: At the precise moment you take off your shoe in a shoe store, your big toe will pop out of your sock to see what's going on. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string manipulation
> Hi I am trying to track down a method for transferring a database id > such as 5 into a nice formatted order id such as ORD0005 - where the > format for the order id is "ORD" + 5 digits made up of the database id See documentation for sprintf(). Try something like: $formatted = sprintf('ORD%05d', $id); - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String manipulation
On Wed, 11 Jun 2003 14:53:13 +0100, Marios Adamantopoulos wrote: >[link][title]the link[/title][address]http://www.php.net[/address][/link] >And I need to change it to this: >http://www.php.net";>the link E, fun try this :) http://www.php.net[/address][/link]'; $out = preg_replace( "|\[link\]\[title\]([^\[]*)\[/title\]\[address\]([^\[]*)\[/address\]\[/link\]|i", "$1", $in ); echo "$in$out" ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String manipulation
Use the substr function to get the part you want. Then prefix/suffix the parts you want. //you may want to derive the positions as vars $rest = substr("abcdef", 1, 3); // returns "bcd" //you may want to put the link name into a var as well for below $rest = "the link" Good Luck, Jake Johnson http://www.plutoid.com On Wed, 11 Jun 2003, Marios Adamantopoulos wrote: > Hi all > > I wonder if anyone can help with this. > I have a piece of copy that includes this: > [link][title]the link[/title][address]http://www.php.net[/address][/link] > And I need to change it to this: > http://www.php.net";>the link > > Any help is appreciated > > Mario > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String Manipulation
On 31-May-2003 S. Cole wrote: > Hello all, > > I'm currently working on a site for my brother-in-law. I have written a > script that will access a website > (http://www.remax.nf.ca/listings.asp?a=163&cp=1) and pull the page into a > variable ($var). I have striped the page down to include only the > listings > > What I want to do, is to be able to work with this data. I don't want to > keep it in the same format as it's on the original site. > > I would like to be able to pull the listings and it's components > separately > so that I can change the layout, color, size, font, etc, etc, etc. > I'd start with : $var=preg_replace('!!m', '[breakhere]', $var); $listing=explode('[breakhere]', $var); Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] string manipulation
This is the best method echo substr(strrchr($string, $char), 1); On 21 February 2003 at 00:13:02, Gregory Heinrichs wrote: > little help please, looking for correct functions to use to search for the > last occurrence of a character in a string and truncate everything in > front of it including the searched for character.< -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] string manipulation
Use strrpos() which will find the last occurrence of something in a string then just use substr() to pull everything from that point on in the string. Kelly -Original Message- From: Gregory Heinrichs [mailto:[EMAIL PROTECTED]] Sent: February 20, 2003 5:13 PM To: [EMAIL PROTECTED] Subject: [PHP] string manipulation little help please, looking for correct functions to use to search for the last occurrence of a character in a string and truncate everything in front of it including the searched for character.< -- 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] string manipulation
Try this (untested): print preg_replace('|<[^<]*$|','$1',$text); Gregory Heinrichs wrote: little help please, looking for correct functions to use to search for the last occurrence of a character in a string and truncate everything in front of it including the searched for character.< -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String manipulation
If you are trying to just validate the email you might also try to the email validation function that php.net uses. You can get it in the CSV area of the site. _ / Joshua Minnie\ ++---+ | Wild Web Technology| | Independent Web Consultant/Developer | | [EMAIL PROTECTED] | || | Tel : 616.890.1566 | ++ "Francisco Vaucher" <[EMAIL PROTECTED]> wrote in message news:3B966ABC166BAF47ACBF4639003B11AC848AE9@;exchange.adtarg.com... : : Yes I know, but what I need is to check after the @. : : I think that regexp it's going to work fine. Erwin wrote something that i : think it's going to work. : : Thanks! : : -Mensaje original- : De: Justin French [mailto:justin@;indent.com.au] : Enviado el: jueves, 24 de octubre de 2002 11:29 : Para: Francisco Vaucher; '[EMAIL PROTECTED]' : Asunto: Re: [PHP] String manipulation : : : Well, what you really trying to do? Validate the format of an email : address? If so, what you really should be doing is looking for an existing : library of code which validates email address formats against the RFC : standard. : : phpclasses.org is bound to have some, but I really like this one: : : http://killersoft.com/modules.php?op=modload&name=News&file=article&sid=2 : : : For your EXACT problem (making sure 'test.com' comes after the @), you could : use regular expressions... BUT [EMAIL PROTECTED] IS a valid email address, : so you'd be running into problems pretty quick :) : : : I looked into HEAPS of regexp's that claim to validate email address'... : HEAPS of them had problems that would bounce VALIDly formatted email : address... the killersoft one is the best I found... : : : : Justin : : : on 25/10/02 12:12 AM, Francisco Vaucher ([EMAIL PROTECTED]) wrote: : : > : > Hi to all (again ;-) : > : > I need one or more PHP functions to handle a form input. : > : > i.e. you write: [EMAIL PROTECTED] : > : > I have to check that after the '@' comes 'test.com'. I think this is easy, : > : > Any help on this ? : > : > regards in advance... : > : > f. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String manipulation
Yes I know, but what I need is to check after the @. I think that regexp it's going to work fine. Erwin wrote something that i think it's going to work. Thanks! -Mensaje original- De: Justin French [mailto:justin@;indent.com.au] Enviado el: jueves, 24 de octubre de 2002 11:29 Para: Francisco Vaucher; '[EMAIL PROTECTED]' Asunto: Re: [PHP] String manipulation Well, what you really trying to do? Validate the format of an email address? If so, what you really should be doing is looking for an existing library of code which validates email address formats against the RFC standard. phpclasses.org is bound to have some, but I really like this one: http://killersoft.com/modules.php?op=modload&name=News&file=article&sid=2 For your EXACT problem (making sure 'test.com' comes after the @), you could use regular expressions... BUT [EMAIL PROTECTED] IS a valid email address, so you'd be running into problems pretty quick :) I looked into HEAPS of regexp's that claim to validate email address'... HEAPS of them had problems that would bounce VALIDly formatted email address... the killersoft one is the best I found... Justin on 25/10/02 12:12 AM, Francisco Vaucher ([EMAIL PROTECTED]) wrote: > > Hi to all (again ;-) > > I need one or more PHP functions to handle a form input. > > i.e. you write: [EMAIL PROTECTED] > > I have to check that after the '@' comes 'test.com'. I think this is easy, > > Any help on this ? > > regards in advance... > > f. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String manipulation
Well, what you really trying to do? Validate the format of an email address? If so, what you really should be doing is looking for an existing library of code which validates email address formats against the RFC standard. phpclasses.org is bound to have some, but I really like this one: http://killersoft.com/modules.php?op=modload&name=News&file=article&sid=2 For your EXACT problem (making sure 'test.com' comes after the @), you could use regular expressions... BUT [EMAIL PROTECTED] IS a valid email address, so you'd be running into problems pretty quick :) I looked into HEAPS of regexp's that claim to validate email address'... HEAPS of them had problems that would bounce VALIDly formatted email address... the killersoft one is the best I found... Justin on 25/10/02 12:12 AM, Francisco Vaucher ([EMAIL PROTECTED]) wrote: > > Hi to all (again ;-) > > I need one or more PHP functions to handle a form input. > > i.e. you write: [EMAIL PROTECTED] > > I have to check that after the '@' comes 'test.com'. I think this is easy, > > Any help on this ? > > regards in advance... > > f. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String Manipulation
>Wow, Thank you for the explanation, it helped out a lot ;) >I don't know regex very well, but I hope that this will give me a better >understanding of it. >Thank you Yet again, >Mike > good luck understanding. personally it is one of those things that I dust off and pull out the help docs everytime I need it... never use it enough to sit down and really become proficient at writing them, and each time I do it is like pulling teeth. Would love to see a nice walkthrough with excercises and such, just havn't bothered. Instead I suffer through each time it must be used to accomplish an end goal. End results from a carefully crafted regex cannot be beat though. Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String Manipulation
Wow, Thank you for the explanation, it helped out a lot ;) I don't know regex very well, but I hope that this will give me a better understanding of it. Thank you Yet again, Mike -Original Message- From: Tech Support [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 25, 2002 12:26 PM To: Mike; PHP List Subject: Re: [PHP] String Manipulation okay... the break down the regexp: '(.*(\(|\[)|(\)|\]).*)' .* = any character from zero to infinite number of times (\(|\[) = either ( or [ (they are escaped with a "\" bcz they have other meaning then I have another pipe "|" meaning "or" (\)|\]) = either ) or ] .* = again... any char any # of times if you want only the parenthesis or the brackets removed just leave out the ".*" in the regexp. the ${$data}was only there in my example working code bcz I had 6 vars named $string1 through $string6. I wanted to call each of them in a loop but you can't say $string$i. I said $data = "string" . $i., which would translate to just a string like this "string1". I could have just used $$data, which is the same as saying $string1 but I hate to use the double "$$" because it looks bad. Sorry if I threw you off. You can just do it like this: $text_out = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', $text_in); Jim Grill Support Web-1 Hosting http://www.web-1hosting.net - Original Message - From: "Mike" <[EMAIL PROTECTED]> To: "'Tech Support'" <[EMAIL PROTECTED]>; "PHP List" <[EMAIL PROTECTED]> Sent: Thursday, July 25, 2002 10:48 AM Subject: RE: [PHP] String Manipulation > Ok, It works and everything, but I just was wondering: > $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data}); > --^ ^ > what does this do exactly, I see that you are replacing all the > characters [] and () but what is the ${$data} for? > Also for future reference is there a way that you could return the > string with all the parentheses stripped out? > Thank You again, > Mike > [EMAIL PROTECTED] > > > And what would be > -Original Message- > From: Tech Support [mailto:[EMAIL PROTECTED]] > Sent: Thursday, July 25, 2002 11:39 AM > To: Mike; PHP List > Subject: Re: [PHP] String Manipulation > > I tested this out with success. > $string = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', $string); > > ### > // Here is actual working code > $string1 = "(Something) - is wrong with me"; > $string2 = "something - (is wrong with me)"; > $string3 = "something - (is wrong with me"; > $string4 = "[something] - is wrong with me"; > $string5 = "something - [is wrong with me]"; > $string6 = "something - [is wrong with me"; > for ($i = 1; $i < 7; $i++) > { > $data = "string" . $i; > $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data}); // the > magic > line. feed it the string(s). > print "$i) $data"; > } > ### > > Jim Grill > Support > Web-1 Hosting > http://www.web-1hosting.net > - Original Message - > From: "Mike" <[EMAIL PROTECTED]> > To: "PHP List" <[EMAIL PROTECTED]> > Sent: Thursday, July 25, 2002 10:13 AM > Subject: [PHP] String Manipulation > > > > Hello all, > > I know that this has probably been discussed before and that you will > > tell me to go through all the back messages on the list but I really > > don't have time to do that because I am on a really tight schedule, > but > > I was wondering if anyone could give me some pointers on how to pull > > some information out of a string. I have something like this: > > (Something) - is wrong with me > > or > > something - (is wrong with me) > > or > > something - (is wrong with me > > > > what I need to know how to do is take the stuff that is inside the > > Brackets (or partial brackets) and put them into another string > > the way I am currently doing it is like this: > > Variable names have been changed per my boss(My Boss wanted me to > change > > them for some reason) > > > $parenpos = strpos($tartist,")"); > > $bracketpos = strpos($tartist,"]"); > > if($parenpos){ > > $artist = trim(substr($tartist,0,$parenpos)); > > $title = trim(substr($tartist,$parenpos+3)); > > $secondparenpos = strpos($title,"("); > > $secondbracketpos = strpos($tartist,"["); > > $title = trim(substr($title,0,$secondparenpos)); > > }elseif($bracketpos){ > > $artist = chop(substr($tartist,1,$bracketpos-1)); > > $title = trim(substr($tartist,$bracketpos+3)); > > } > > ?> > > > > I know that there has to be a shorter version of this, can anyone help > > me out with it? > > > > Thank You, > > Mike > > [EMAIL PROTECTED] > > [EMAIL PROTECTED] > > > > > > -- > > 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 > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Manipulation
okay... the break down the regexp: '(.*(\(|\[)|(\)|\]).*)' .* = any character from zero to infinite number of times (\(|\[) = either ( or [ (they are escaped with a "\" bcz they have other meaning then I have another pipe "|" meaning "or" (\)|\]) = either ) or ] .* = again... any char any # of times if you want only the parenthesis or the brackets removed just leave out the ".*" in the regexp. the ${$data}was only there in my example working code bcz I had 6 vars named $string1 through $string6. I wanted to call each of them in a loop but you can't say $string$i. I said $data = "string" . $i., which would translate to just a string like this "string1". I could have just used $$data, which is the same as saying $string1 but I hate to use the double "$$" because it looks bad. Sorry if I threw you off. You can just do it like this: $text_out = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', $text_in); Jim Grill Support Web-1 Hosting http://www.web-1hosting.net - Original Message - From: "Mike" <[EMAIL PROTECTED]> To: "'Tech Support'" <[EMAIL PROTECTED]>; "PHP List" <[EMAIL PROTECTED]> Sent: Thursday, July 25, 2002 10:48 AM Subject: RE: [PHP] String Manipulation > Ok, It works and everything, but I just was wondering: > $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data}); > --^ ^ > what does this do exactly, I see that you are replacing all the > characters [] and () but what is the ${$data} for? > Also for future reference is there a way that you could return the > string with all the parentheses stripped out? > Thank You again, > Mike > [EMAIL PROTECTED] > > > And what would be > -Original Message- > From: Tech Support [mailto:[EMAIL PROTECTED]] > Sent: Thursday, July 25, 2002 11:39 AM > To: Mike; PHP List > Subject: Re: [PHP] String Manipulation > > I tested this out with success. > $string = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', $string); > > ### > // Here is actual working code > $string1 = "(Something) - is wrong with me"; > $string2 = "something - (is wrong with me)"; > $string3 = "something - (is wrong with me"; > $string4 = "[something] - is wrong with me"; > $string5 = "something - [is wrong with me]"; > $string6 = "something - [is wrong with me"; > for ($i = 1; $i < 7; $i++) > { > $data = "string" . $i; > $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data}); // the > magic > line. feed it the string(s). > print "$i) $data"; > } > ### > > Jim Grill > Support > Web-1 Hosting > http://www.web-1hosting.net > - Original Message - > From: "Mike" <[EMAIL PROTECTED]> > To: "PHP List" <[EMAIL PROTECTED]> > Sent: Thursday, July 25, 2002 10:13 AM > Subject: [PHP] String Manipulation > > > > Hello all, > > I know that this has probably been discussed before and that you will > > tell me to go through all the back messages on the list but I really > > don't have time to do that because I am on a really tight schedule, > but > > I was wondering if anyone could give me some pointers on how to pull > > some information out of a string. I have something like this: > > (Something) - is wrong with me > > or > > something - (is wrong with me) > > or > > something - (is wrong with me > > > > what I need to know how to do is take the stuff that is inside the > > Brackets (or partial brackets) and put them into another string > > the way I am currently doing it is like this: > > Variable names have been changed per my boss(My Boss wanted me to > change > > them for some reason) > > > $parenpos = strpos($tartist,")"); > > $bracketpos = strpos($tartist,"]"); > > if($parenpos){ > > $artist = trim(substr($tartist,0,$parenpos)); > > $title = trim(substr($tartist,$parenpos+3)); > > $secondparenpos = strpos($title,"("); > > $secondbracketpos = strpos($tartist,"["); > > $title = trim(substr($title,0,$secondparenpos)); > > }elseif($bracketpos){ > > $artist = chop(substr($tartist,1,$bracketpos-1)); > > $title = trim(substr($tartist,$bracketpos+3)); > > } > > ?> > > > > I know that there has to be a shorter version of this, can anyone help > > me out with it? > > > > Thank You, > > Mike > > [EMAIL PROTECTED] > > [EMAIL PROTECTED] > > > > > > -- > > 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 > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String Manipulation
Ok, It works and everything, but I just was wondering: $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data}); --^ ^ what does this do exactly, I see that you are replacing all the characters [] and () but what is the ${$data} for? Also for future reference is there a way that you could return the string with all the parentheses stripped out? Thank You again, Mike [EMAIL PROTECTED] And what would be -Original Message- From: Tech Support [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 25, 2002 11:39 AM To: Mike; PHP List Subject: Re: [PHP] String Manipulation I tested this out with success. $string = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', $string); ### // Here is actual working code $string1 = "(Something) - is wrong with me"; $string2 = "something - (is wrong with me)"; $string3 = "something - (is wrong with me"; $string4 = "[something] - is wrong with me"; $string5 = "something - [is wrong with me]"; $string6 = "something - [is wrong with me"; for ($i = 1; $i < 7; $i++) { $data = "string" . $i; $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data}); // the magic line. feed it the string(s). print "$i) $data"; } ### Jim Grill Support Web-1 Hosting http://www.web-1hosting.net - Original Message - From: "Mike" <[EMAIL PROTECTED]> To: "PHP List" <[EMAIL PROTECTED]> Sent: Thursday, July 25, 2002 10:13 AM Subject: [PHP] String Manipulation > Hello all, > I know that this has probably been discussed before and that you will > tell me to go through all the back messages on the list but I really > don't have time to do that because I am on a really tight schedule, but > I was wondering if anyone could give me some pointers on how to pull > some information out of a string. I have something like this: > (Something) - is wrong with me > or > something - (is wrong with me) > or > something - (is wrong with me > > what I need to know how to do is take the stuff that is inside the > Brackets (or partial brackets) and put them into another string > the way I am currently doing it is like this: > Variable names have been changed per my boss(My Boss wanted me to change > them for some reason) > $parenpos = strpos($tartist,")"); > $bracketpos = strpos($tartist,"]"); > if($parenpos){ > $artist = trim(substr($tartist,0,$parenpos)); > $title = trim(substr($tartist,$parenpos+3)); > $secondparenpos = strpos($title,"("); > $secondbracketpos = strpos($tartist,"["); > $title = trim(substr($title,0,$secondparenpos)); > }elseif($bracketpos){ > $artist = chop(substr($tartist,1,$bracketpos-1)); > $title = trim(substr($tartist,$bracketpos+3)); > } > ?> > > I know that there has to be a shorter version of this, can anyone help > me out with it? > > Thank You, > Mike > [EMAIL PROTECTED] > [EMAIL PROTECTED] > > > -- > 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] String Manipulation
Thanks, it worked like a charm ;) Mike -Original Message- From: Tech Support [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 25, 2002 11:39 AM To: Mike; PHP List Subject: Re: [PHP] String Manipulation I tested this out with success. $string = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', $string); ### // Here is actual working code $string1 = "(Something) - is wrong with me"; $string2 = "something - (is wrong with me)"; $string3 = "something - (is wrong with me"; $string4 = "[something] - is wrong with me"; $string5 = "something - [is wrong with me]"; $string6 = "something - [is wrong with me"; for ($i = 1; $i < 7; $i++) { $data = "string" . $i; $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data}); // the magic line. feed it the string(s). print "$i) $data"; } ### Jim Grill Support Web-1 Hosting http://www.web-1hosting.net - Original Message - From: "Mike" <[EMAIL PROTECTED]> To: "PHP List" <[EMAIL PROTECTED]> Sent: Thursday, July 25, 2002 10:13 AM Subject: [PHP] String Manipulation > Hello all, > I know that this has probably been discussed before and that you will > tell me to go through all the back messages on the list but I really > don't have time to do that because I am on a really tight schedule, but > I was wondering if anyone could give me some pointers on how to pull > some information out of a string. I have something like this: > (Something) - is wrong with me > or > something - (is wrong with me) > or > something - (is wrong with me > > what I need to know how to do is take the stuff that is inside the > Brackets (or partial brackets) and put them into another string > the way I am currently doing it is like this: > Variable names have been changed per my boss(My Boss wanted me to change > them for some reason) > $parenpos = strpos($tartist,")"); > $bracketpos = strpos($tartist,"]"); > if($parenpos){ > $artist = trim(substr($tartist,0,$parenpos)); > $title = trim(substr($tartist,$parenpos+3)); > $secondparenpos = strpos($title,"("); > $secondbracketpos = strpos($tartist,"["); > $title = trim(substr($title,0,$secondparenpos)); > }elseif($bracketpos){ > $artist = chop(substr($tartist,1,$bracketpos-1)); > $title = trim(substr($tartist,$bracketpos+3)); > } > ?> > > I know that there has to be a shorter version of this, can anyone help > me out with it? > > Thank You, > Mike > [EMAIL PROTECTED] > [EMAIL PROTECTED] > > > -- > 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String Manipulation
I tested this out with success. $string = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', $string); ### // Here is actual working code $string1 = "(Something) - is wrong with me"; $string2 = "something - (is wrong with me)"; $string3 = "something - (is wrong with me"; $string4 = "[something] - is wrong with me"; $string5 = "something - [is wrong with me]"; $string6 = "something - [is wrong with me"; for ($i = 1; $i < 7; $i++) { $data = "string" . $i; $data = ereg_replace('(.*(\(|\[)|(\)|\]).*)', '', ${$data}); // the magic line. feed it the string(s). print "$i) $data"; } ### Jim Grill Support Web-1 Hosting http://www.web-1hosting.net - Original Message - From: "Mike" <[EMAIL PROTECTED]> To: "PHP List" <[EMAIL PROTECTED]> Sent: Thursday, July 25, 2002 10:13 AM Subject: [PHP] String Manipulation > Hello all, > I know that this has probably been discussed before and that you will > tell me to go through all the back messages on the list but I really > don't have time to do that because I am on a really tight schedule, but > I was wondering if anyone could give me some pointers on how to pull > some information out of a string. I have something like this: > (Something) - is wrong with me > or > something - (is wrong with me) > or > something - (is wrong with me > > what I need to know how to do is take the stuff that is inside the > Brackets (or partial brackets) and put them into another string > the way I am currently doing it is like this: > Variable names have been changed per my boss(My Boss wanted me to change > them for some reason) > $parenpos = strpos($tartist,")"); > $bracketpos = strpos($tartist,"]"); > if($parenpos){ > $artist = trim(substr($tartist,0,$parenpos)); > $title = trim(substr($tartist,$parenpos+3)); > $secondparenpos = strpos($title,"("); > $secondbracketpos = strpos($tartist,"["); > $title = trim(substr($title,0,$secondparenpos)); > }elseif($bracketpos){ > $artist = chop(substr($tartist,1,$bracketpos-1)); > $title = trim(substr($tartist,$bracketpos+3)); > } > ?> > > I know that there has to be a shorter version of this, can anyone help > me out with it? > > Thank You, > Mike > [EMAIL PROTECTED] > [EMAIL PROTECTED] > > > -- > 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] String Manipulation
Maybe something like: eregi('([a-z]*)( *)(\(*)([a-z]+)( *)(\)*)([a-z]*)',$string,$matches); echo $matches[4]; Op donderdag 25 juli 2002 17:13, schreef Mike: > Hello all, > I know that this has probably been discussed before and that you will > tell me to go through all the back messages on the list but I really > don't have time to do that because I am on a really tight schedule, but > I was wondering if anyone could give me some pointers on how to pull > some information out of a string. I have something like this: > (Something) - is wrong with me > or > something - (is wrong with me) > or > something - (is wrong with me > > what I need to know how to do is take the stuff that is inside the > Brackets (or partial brackets) and put them into another string > the way I am currently doing it is like this: > Variable names have been changed per my boss(My Boss wanted me to change > them for some reason) > $parenpos = strpos($tartist,")"); > $bracketpos = strpos($tartist,"]"); > if($parenpos){ > $artist = trim(substr($tartist,0,$parenpos)); > $title = trim(substr($tartist,$parenpos+3)); > $secondparenpos = strpos($title,"("); > $secondbracketpos = strpos($tartist,"["); > $title = trim(substr($title,0,$secondparenpos)); > }elseif($bracketpos){ > $artist = chop(substr($tartist,1,$bracketpos-1)); > $title = trim(substr($tartist,$bracketpos+3)); > } > ?> > > I know that there has to be a shorter version of this, can anyone help > me out with it? > > Thank You, > Mike > [EMAIL PROTECTED] > [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String manipulation with ereg_replace
On Thursday 22 February 2001 23:42, Simon Garner wrote: > This should do the trick (untested!): > > $contents = " alt=ThisOneReallyNeedsToBeAllLowercase.gif>"; > > $contents = preg_replace("/([-_a-zA-Z0-9]+)\.gif/e", > "strtolower('\\1') . '.gif'", $contents); > ?> simpler that "/([-_a-zA-Z0-9]+)\.gif/e" is "/([-\w]+)\.gif/e" -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) Google results 1-10 of about 142,000,000 for e. Search took 0.18 seconds. - http://www.google.com/search?q=e -- 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]
Re: [PHP] String manipulation with ereg_replace
From: "Ian LeBlanc" <[EMAIL PROTECTED]> > > I am working on a site that has over 1000 pages and all the images need to > be made lower case in the HTML. > Here is what I have so far. Please someone tell me what I am doing wrong. > > > $contents=" alt=ThisOneReallyNeedsToBeAllLowercase.gif>"; > > $contents = EREG_REPLACE("([-_a-zA-Z0-9]+).gif",strtolower("\\0"),$contents); > > > Output of $contents needs to equal > alt=thisonereallyneedstobealllowercase.gif> > > You need to use preg_replace which supports evaluating PHP code for the replacement. To use preg functions you need to have compiled PHP with PCRE (Perl Compatible Regular Expression) support. http://www.php.net/manual/function.preg-replace.php3 This should do the trick (untested!): "; $contents = preg_replace("/([-_a-zA-Z0-9]+)\.gif/e", "strtolower('\\1') . '.gif'", $contents); ?> Cheers Simon Garner -- 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]