How to get a string between 2 characters

I have a text value for date in this format “2010-01-30”.

When a day or month is not known, I have it shown as zero: “2010-0-0”

I now want to assign each part of this value, as 3 separate values which I will assign to $rYear, $rMonth, $rDay.

I can’t figure out how to get the value between the dashes for the month. I don’t think there is a php method that does this?

I have looked at some example functions people have written, but nothing that matches my scenario.

Could someone please help me out with this.

I also need to figure out a way to get the last digit for days, but hopefully once I figure out how to get the month value, I should be able to figure out how to get the day value.

Thank you.

I appear to have it working. Here’s what I did:

$first = strpos($str,"-") + 1;
$second = strrpos($str,"-") - $first;
echo substr($str,$first,$second)

See explode() and if you must store the pieces in discrete variables, rather than in elements of an array, see list().

Thanks phdr,

I became rather fixated in trying to store my text value in a “date appearance” that I overlooked the idea of just storing the date elements as an array. I have not used the list() method before, and I think it could work well if I store the date info as an array.

Sponsor our Newsletter | Privacy Policy | Terms of Service