I have a data string that starts with a combination of upper/lower case letters, numbers, hyphen and period. The length of this part of the string is quite variable, do I’d like to use preg_match() to capture just this first portion of the string.
<code>
$string = ‘IN-A-103P-C Fly, C. S. Indian Camp; 1886 1886 C.S. Fly Photographer HP Photographs ina103pc.jpg Apache Indians’;
[QUOTE=centered effect;4955588]Why not use explode if it will always be at the first portion of the string followed by a space?
Tried that, but that space isn’t a " ", it’s some other kind of whitespace. Since I can’t figure out what kind of whitespace it is, it seems simple to do the pre_match() method. Then simply stop when a character is not A-Z, a-z, o-9, or -, or a period.
Just remove the $ at the end of your pattern. The $ means “the end of the match must be at the end of the string”. You don’t want this, so you can remove that. You should leave the ^ though, because you want the start of the match to be at the start of the subject string
Tried that, but that space isn’t a " ", it’s some other kind of whitespace. Since I can’t figure out what kind of whitespace it is, it seems simple to do the pre_match() method. Then simply stop when a character is not A-Z, a-z, o-9, or -, or a period.[/QUOTE]
Sorry, I should have read that the first time. You could also replace the white space with a space as well, then explode it.
$string = preg_replace(“‘\s+’”, ’ ', $string);
This works great, Gvre. Thank you!
Could you take a moment to explain in plain English what’s happening here?? Then I’ll have a better understanding for next time I run into a similar issue.
“Split the variable $string, using anything that isnt a-z,0-9,\, or - as a delimiter, and returning at most 2 parts (IE: Only do the first such split.).”
An easy way would be to show us the output of echo base64_encode($string). At least that way we can determine the actual contents, which would be a great start.