I have a list of items that are in this format:
05/01 – Some Basic: Text Here (Alpha, Bravo, Charli)
The first part is a date, then its always followed by a – . Then some text which represents a title or location of some sort and then some keywords that may or may not be in the parentheses.
I want to be able to extract the $month the $day the $title (including any colons) and the $keyword1 $keyword2 $keyword3 if they are there. Then assign them all to individual variables like the ones I’ve created so I can add them into my database. Getting it to do one of these at a time would be a great start but ultimately I want to be able to paste in multiple items in that format(without any spaces or characters to mark the difference besides whats already there) and be able to bulk extract them.
I’ve tried to use Preg_Match_all and things like stristr() but am having difficulty. I don’t really understand how to use them to get the specific parts.
For example
$month = stristr($listItem, '/', true);
echo"$month<br />";
$preDay = stristr($listItem, 'The', true);
echo"$preDay<br />";
$day = stristr($preDay, '/', false);
echo"$day<br />";
This only outputs this:
05
05/01 –
/01 –
^ I can’t have the / or any weird –.
Actual code and an explanation of how to do this would be awesome! If you are using pregmatch I would really appreciate a breakdown of how your filtering this. Thank you much.
The easiest way is using explode().
The explode() function provides a fast way to break strings into arrays. See the manual: http://php.net/manual/pt_BR/function.explode.php
With this format of string, you can break it into an array as follows.
I don’t know if this is the best way but it works. You can also try using preg_split() function. This function makes a split using regular expressions. If you need help on regular expressions see http://www.phpf1.com/tutorial/php-regular-expression.html
EDIT 1 I noticed that you string contains this symbol “–” after the date. This is not a hyphen as I know it. I use the minus signal to write it on my keyboard.
Your simbol / mine = –-
They are a little bit different.