elentz Posted April 20, 2018 Share Posted April 20, 2018 I have a md5sum txt file that might look something like this 4cf85bad582597cca7fc030ce73cdb72 A11-V2.5.3.c8fd0.fw I want to take the hash and the file name and insert them into a MySql table as two separate entries. How do I separate the two and get them into variables so I can insert them into my db? Are there any tutorials out there that will help me? Thanks Quote Link to comment Share on other sites More sharing options...
Solution ginerjm Posted April 20, 2018 Solution Share Posted April 20, 2018 There's probably more elegant ways but I would do a strpos on the string looking for a space. Then I would grab the beginning part up to that position for the hash and then grab the part after that position for the filename. Do a trim on each to get rid of any other chars. $pos = strpos($string,' '); $value = trim(substr($string,0,$pos)); $filename = trim(substr($string,$pos)); Quote Link to comment Share on other sites More sharing options...
elentz Posted April 20, 2018 Author Share Posted April 20, 2018 Thanks for the reply. I tried this with only getting the file location <?php $string = ("/home/PhoneFirmware/100/md5.txt"); $pos = strpos($string,' '); $value = trim(substr($string,0,$pos)); $filename = trim(substr($string,$pos)); echo $value; echo $filename; ?> Alternatively if you can shoe me how I can get the file name in a directory. There will ONLY be one file in the directory in question. I can run the md5sum to get the value of the hash and I can get that to work the way I need it. Quote Link to comment Share on other sites More sharing options...
phpmillion Posted April 21, 2018 Share Posted April 21, 2018 Well, that's because your $string variable is this text - "/home/PhoneFirmware/100/md5.txt" If you want to get content of file (not the location of file), use file_get_contents function. Your first line of code should be: $string=file_get_contents("/home/PhoneFirmware/100/md5.txt"); Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 21, 2018 Share Posted April 21, 2018 You did a switcheroo on me! First you said your argument was a bit of data then you show us a string that is not THAT! Quote Link to comment Share on other sites More sharing options...
elentz Posted April 23, 2018 Author Share Posted April 23, 2018 You did a switcheroo on me! First you said your argument was a bit of data then you show us a string that is not THAT! Oops, sorry Been battling a head code and some of this is working through a fog. My apologies Quote Link to comment Share on other sites More sharing options...
elentz Posted April 23, 2018 Author Share Posted April 23, 2018 Oops, sorry Been battling a head code and some of this is working through a fog. My apologies Thanks guys changing the first line as phpmillion suggested works perfectly. Thank you for all your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.