On 15 Mar 2004 Eric Gorr wrote:
> >which will have a value like: 98797-234234--2c-something-2c
> >
> >How do I take out the part which will always start with "--2c" and will
> >always end with "-2c"
>
> I'd be interested in the answer to this question as well.
> Seems like it should be easy.
It is easy. I agree with whoever said string functions were a better
solution, regexp is overkill unless there is more variaiton in the data
than what was presented. That said, here are some possibilities; all
but the first assume that the "--" is always there:
- If the lengths are constant just use substr to pull out the
first 11 characters.
- Find the "--" with strpos and then use that in a substr call to
take just the part to the left.
- Use explode to separate the string at the "--" or "--2c".
- For two numeric strings separated by a dash use a regexp
approach something like this:
if (preg_match("/^(\d*-\d*)--2c/", $string, $matches))
$left_part = $matches[1];
--
Tom
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php