louis_coetzee Posted June 26, 2009 Share Posted June 26, 2009 Please help me, I want to read the values between the red text into different variables, for example: |ACTIV|gvnE8HEsyivRyirwE|TRIME| =....... $active = gvnE8HEsyivRyirwE (|ACTIV|gvnE8HEsyivRyirwE|TRIME|wpxFGswFxmJdcJF|CLAS1|gUGJxfJd|CLAS2|gUGJxfJd|SEVER| Quote Link to comment https://forums.phpfreaks.com/topic/163776-string-copy-function-help/ Share on other sites More sharing options...
Alex Posted June 26, 2009 Share Posted June 26, 2009 Assuming all the spacers are 7 characters long (as they are in your example) You can use this: $string = '|ACTIV|gvnE8HEsyivRyirwE|TRIME|wpxFGswFxmJdcJF|CLAS1|gUGJxfJd|CLAS2|gUGJxfJd|SEVER|'; $split = str_split($string); $parts = Array(); $j = -1; for($i = 0;$i < count($split)-7;$i++) { if($split[$i] == '|'){ $i += 7; $j++;} $parts[$j] .= $split[$i]; } echo $parts[0] . '<br />'; //gvnE8HEsyivRyirwE echo $parts[1] . '<br />'; //wpxFGswFxmJdcJF echo $parts[2] . '<br />'; //gUGJxfJd echo $parts[3] . '<br />'; //gUGJxfJd You could probably also use Regex, I might post a regex solution in a few minutes. Quote Link to comment https://forums.phpfreaks.com/topic/163776-string-copy-function-help/#findComment-864161 Share on other sites More sharing options...
louis_coetzee Posted June 26, 2009 Author Share Posted June 26, 2009 Assuming all the spacers are 7 characters long (as they are in your example) You can use this: $string = '|ACTIV|gvnE8HEsyivRyirwE|TRIME|wpxFGswFxmJdcJF|CLAS1|gUGJxfJd|CLAS2|gUGJxfJd|SEVER|'; $split = str_split($string); $parts = Array(); $j = -1; for($i = 0;$i < count($split)-7;$i++) { if($split[$i] == '|'){ $i += 7; $j++;} $parts[$j] .= $split[$i]; } echo $parts[0] . '<br />'; //gvnE8HEsyivRyirwE echo $parts[1] . '<br />'; //wpxFGswFxmJdcJF echo $parts[2] . '<br />'; //gUGJxfJd echo $parts[3] . '<br />'; //gUGJxfJd You could probably also use Regex, I might post a regex solution in a few minutes. Hi Alex, Thanks a lot for your reply, the only problem would be that that was only part of one string, they differ eatch time, basically its all encrypted, except for the 7char part... for example:(below) I need to assighn eatch to a variable for example: |ACTIV| would be $active and the rest that follows, until the next one. basically need to take this, decrypt it, and display is in catagories in a table. ("|ACTIV|gLrS8wiSv0tg8H|TRIME|wpxFGswFxmJdcJF|CLAS1|nFbTdslddU9xlcJGsYxcpspJhlcUcU x9xce.|CLAS2|pJhlcUcU x9slTJfcd|SEVER|oJslYlFJsU2scpJsFxdN!|DESCR|yFJTflf9esxf9FJldJdscpJsFxdNscUsGJPJjUhspJhlcUcU x9xce.s82sGFbTsxdsmJcluUjxCJGsxfscpJsjxPJF,slPUxGsGFbTdsYxcpslsjUfTsGbFlcxUfsU2sl9cxUf.soJdcsxdscUsdJJNsGFbTsfUcsmJcluUjxCJGsxfsjxPJF.|SPRIO|2")(|ACTIV|gLrS8wiSv0tg8H|TRIME|wpxFGswFxmJdcJF|CLAS1|H6LL|CLAS2|0ldcJFsDFUbh:sgLrS8wiSv0tg8H|SEVER|6dJsGFbTsUfjesYpJFJscpJsuJfJ2xcsqbdcx2xJdscpJsFxdNscUscpJs2Jcbd.swpJsGFbTsGUJds9lFFeslsFxdN.|DESCR|SxdNs2l9cUFsgs:srfxmljsdcbGxJdsdbTTJdcspxTpsFxdNs-sjxmxcJGspbmlfsGlclslPlxjlujJ.soJdcslPUxGJG.|SPRIO|3)("|ACTIV|gLrS8wiSv0tg8H|TRIME|RJ9UfGswFxmJdcJF|CLAS1|nFbTdslddU9xlcJGsYxcpspJhlcUcU x9xce.|CLAS2|pJhlcUcU x9slTJfcd|SEVER|oJslYlFJsU2scpJsFxdN!|DESCR|yFJTflf9esxf9FJldJdscpJsFxdNscUsGJPJjUhspJhlcUcU x9xce.s82sGFbTsxdsmJcluUjxCJGsxfscpJsjxPJF,slPUxGsGFbTdsYxcpslsjUfTsGbFlcxUfsU2sl9cxUf.soJdcsxdscUsdJJNsGFbTsfUcsmJcluUjxCJGsxfsjxPJF.|SPRIO|2")(|ACTIV|gLrS8wiSv0tg8H|TRIME|RJ9UfGswFxmJdcJF|CLAS1|H6LL|CLAS2|0ldcJFsDFUbh:sgLrS8wiSv0tg8H|SEVER|6dJsGFbTsUfjesYpJFJscpJsuJfJ2xcsqbdcx2xJdscpJsFxdNscUscpJs2Jcbd.swpJsGFbTsGUJds9lFFeslsFxdN.|DESCR|SxdNs2l9cUFsgs:srfxmljsdcbGxJdsdbTTJdcspxTpsFxdNs-sjxmxcJGspbmlfsGlclslPlxjlujJ.soJdcslPUxGJG.|SPRIO|3)("|ACTIV|gLrS8wiSv0tg8H|TRIME|1xFdcswFxmJdcJF|CLAS1|nFbTdslddU9xlcJGsYxcpspJhlcUcU x9xce.|CLAS2|pJhlcUcU x9slTJfcd|SEVER|oJslYlFJsU2scpJsFxdN!|DESCR|yFJTflf9esxf9FJldJdscpJsFxdNscUsGJPJjUhspJhlcUcU x9xce.s82sGFbTsxdsmJcluUjxCJGsxfscpJsjxPJF,slPUxGsGFbTdsYxcpslsjUfTsGbFlcxUfsU2sl9cxUf.soJdcsxdscUsdJJNsGFbTsfUcsmJcluUjxCJGsxfsjxPJF.|SPRIO|2")(|ACTIV|gLrS8wiSv0tg8H|TRIME|1xFdcswFxmJdcJF|CLAS1|H6LL|CLAS2|0ldcJFsDFUbh:sgLrS8wiSv0tg8H|SEVER|6dJsGFbTsUfjesYpJFJscpJsuJfJ2xcsqbdcx2xJdscpJsFxdNscUscpJs2Jcbd.swpJsGFbTsGUJds9lFFeslsFxdN.|DESCR|SxdNs2l9cUFsgs:srfxmljsdcbGxJdsdbTTJdcspxTpsFxdNs-sjxmxcJGspbmlfsGlclslPlxjlujJ.soJdcslPUxGJG.|SPRIO|3) Quote Link to comment https://forums.phpfreaks.com/topic/163776-string-copy-function-help/#findComment-864163 Share on other sites More sharing options...
Alex Posted June 26, 2009 Share Posted June 26, 2009 Mine will work fine, it only shows the last couple because that's what I put it to do, instead just remove those echos, and put print_r($parts); when you run it on the full string it'll show the array that contains all the parts. Quote Link to comment https://forums.phpfreaks.com/topic/163776-string-copy-function-help/#findComment-864168 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.