VERY new to PHP, or any programming language for that matter. So far I'm gettig by thanks to google search and my reference book for help. This one I'm sure is very simple, but can't seem to find anything... Im using the "explode" function but need to put a variable in the string separator immediately following some text. Don't know how to do this... $var = some number $array = explode('sometext$var',$string); meaning, my stringseparator varries while in a loop depending on the value of $var, but is appended to some various text. So lets say $var is equal to 20 in this loop. then the string separator would be "sometext20", but next loop it would be "sometext21" what is the proper format of the string separator? Thanks
Heh, what you want. If you want explode word "something" where is letter 'e', you would do this explode('e',"something"); and the result will be 2 values in array, "som" and "thing". Clear now?
No.. I guess I'm not clear.... I know how explode works, but this time I am using it while in a loop, where the string separator will change each time through the loop. lets say I had this data... First Time through the loop when $var=20 $x = 3020t30t203030 Second time through the loop when $var=19 $x - 3020t30t193030 So the value after the second "t" changes each time... and this is exactly where I want my string separator. So, I want the number following the second "t" in the string to be a variable b/c it can change each time through $array = explode ('t$var',$x); Follow me now? What is the appropriate syntax in the string separator? Thanks
If you use double quotes " PHP will output the contents/value of $var instead of the string '$var' $array = explode ("t$var",$x); You can also use: $array = explode ('t'.$var,$x); The double quotes works for every function and on echo, etc... <?php $name = 'themole'; echo 'Hello $name!'; //This outputs Hello $name! echo "Hello $name!"; //This outputs Hello themole! echo 'Hello '.$name.'!'; //This also outputs Hello themole! ?> Code (markup): -the mole
I even didn't know, this was your problem, because your first line looks like pseudocode, so I predict the second is also.
Sorry frisby... I really don't yet know the protocol of posting code questions that are understandable. I'll get there as I'm sure I'll have more questions. Thanks for the quick replies.