finding first instance
Brain gone dead
$str = "re: this is a reply";
$pieces = explode("re:", $str);
echo $pieces[0]; // re:
problem:
explode can be anywhere in the string - need it to be first instance only, not pick up "this is not a re:"
Also I don't think explode picks up the ':'
Like I said, brain gone dead so any advise or helpful suggestions welcomed
Thanks
timjpriebe posted this at 12:47 — 1st April 2005.
He has: 2,667 posts
Joined: Dec 2004
Sounds like Perl would be perfect for this...
I'm not nearly as familiar with PHP, but I know in Perl you might have to put a backslash before the ":" to get Perl to recognize it.
Tim
http://www.tandswebdesign.com
dk01 posted this at 16:03 — 1st April 2005.
He has: 516 posts
Joined: Mar 2002
Check out the strpos() function and the substr() function.
Together I am sure they can do what you are looking for.
-dk
Greg K posted this at 16:23 — 1st April 2005.
He has: 2,145 posts
Joined: Nov 2003
I'm missing what you are actually trying to get from this example. (hey I just woke up, so I might be the brain dead one right now
From your example you are just wanting to see if it starts with RE: or RE: is one of the things you are looking for? Are you just needing to get up to the first colon if it exists (so you can get RE: and FWD: ?)
-Greg
Busy posted this at 09:50 — 2nd April 2005.
He has: 6,151 posts
Joined: May 2001
Thanks dk01, could be what I was looking for.
Greg K, am trying to find if the strings starts with 're:' (as in reply), but not return a result if included elsewhere in the string.
Busy posted this at 10:34 — 2nd April 2005.
He has: 6,151 posts
Joined: May 2001
Solution:
$str = "re: this is the topic";
$re = substr("$str", 0, 3);
if($re == 're:')
{
echo "this string starts with re:";
}
dk01 posted this at 17:42 — 2nd April 2005.
He has: 516 posts
Joined: Mar 2002
Remember to use the trim() function too just incase there is a leading space
Glad to see you got what you were looking for!
-dk
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.