php - Split document by specific character, then split further into vars -


I am trying to do the job that I have the best to split some data. Whether in more than one different arrays, or nested arrays, or something different.

I have a file that holds titles, file names and dates for many different items. Each item is separated with the ^ character, and each part of the list is different with the tilde ~

Looks like this:

  After example, an example-one-one ~ Friday, October 17, 2014 ^ wifining for the mobile web ~ for the route-pand-mobile-web ~ Friday 17 October 2014 ^  

I created a function that captures the data and divides it into an array using ^ Interpretation is:

  function getPostList () {$ Masterposts = "../posts/master-allposts.txt"; $ Current = file_get_contents ($ masterposts); $ Masterpostlist = Explosion ('^', $ current); Return $ masterpostlist; }  

And the result is something like this:

  array (3) {[0] => String (46) "Example Post One ~ Example-One-One ~ Friday 17 October 2014" [1] => String (83) "Campaign for Mobile Web Campaign - Wetfanding-to-Mobile-Web" Friday, October 17, 2014 "[2] = & gt; String (0) ""}  

However now I am trying to break that array so that I can produce all the different parts for each. Ideally, the string wars $ title, $ filename and $ publishdate

I have found this much but I think I'm running into problems because I use the array every time I'm overwriting. How would you do this?

  foreach ($ masterpostlist as post $) {$ postParts = explode ('~', $ post); Var_dump ($ postParts); }     

You basically change the original position and convert the already existing array to "Convert " can do. Explosive variables with explosions

  foreach ($ masterpostlist & amp; $ post) {$ post = explode ('~', $ post); }  

This reference & amp; uses the operator and allows the code inside the foreach loop to change the loop's variable. Otherwise it will only replace the temporary copy used inside the loop.

In your function, it will be used like this:

  function getPostList () {$ masterposts = "../posts/master-allposts.txt"; $ Current = file_get_contents ($ masterposts); $ Masterpostlist = Explosion ('^', $ current); Forex Currency ($ masterpostlist & amp; $ post) {$ post = explode ('~', $ post); } Return $ masterpostlist; }  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -