jacko310592 Posted November 27, 2009 Share Posted November 27, 2009 hey guys, can someone please tell me how to put data from the glob function into a string thanks Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/ Share on other sites More sharing options...
Daniel0 Posted November 27, 2009 Share Posted November 27, 2009 <?php $array = glob('something'); $str = ''; for ($i = 0; $l = sizeof($array); $i < $l; ++$i) { $a = str_rot13($array[$i]) . strrev($array[$i*3%$l]); $b = ''; for ($j = 0, $c = strlen($a); $j < $c; ++$j) { $b .= $j % 2 ? $a[$j] : ''; } $str .= $b; } echo $str; Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966630 Share on other sites More sharing options...
jacko310592 Posted November 27, 2009 Author Share Posted November 27, 2009 hey Daniel0, thanks for helping but it came back with an error on this line... for ($i = 0; $l = sizeof($array); $i < $l; ++$i) { error was: Parse error: syntax error, unexpected ';', expecting ')' Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966641 Share on other sites More sharing options...
Alex Posted November 27, 2009 Share Posted November 27, 2009 One of the ;'s should be a comma: for ($i = 0, $l = sizeof($array); $i < $l; ++$i) { Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966642 Share on other sites More sharing options...
jacko310592 Posted November 27, 2009 Author Share Posted November 27, 2009 thanks (: another problem, the out put was nonsense... yh.uppmbayragiscdrrvgeasnlbxsagthqgppmbaar.uscdnqpcfeasnlbrafephrsagthvu_ugtnuppmbaugtnfkobgngespcdahr_nesagth when what it should be saying is the names of my folders Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966644 Share on other sites More sharing options...
Daniel0 Posted November 27, 2009 Share Posted November 27, 2009 You didn't say that. You just said you wanted a string. Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966646 Share on other sites More sharing options...
Alex Posted November 27, 2009 Share Posted November 27, 2009 Yea, that's what should be expected by that code. Daniel0 was just messing with you. You really didn't specify how you want the string to be constructed. What Daniel0 gave you technically does produce 'a string' from the result of glob() Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966648 Share on other sites More sharing options...
jacko310592 Posted November 27, 2009 Author Share Posted November 27, 2009 oh, okay XD my intention was to use the glob to get the folder names sorry i didnt state that Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966650 Share on other sites More sharing options...
Daniel0 Posted November 27, 2009 Share Posted November 27, 2009 http://php.net/foreach Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966651 Share on other sites More sharing options...
Alex Posted November 27, 2009 Share Posted November 27, 2009 $str = ''; foreach(glob("*", GLOB_ONLYDIR) as $dir) $str .= "$dir<br />\n"; echo $str; Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966654 Share on other sites More sharing options...
jacko310592 Posted November 27, 2009 Author Share Posted November 27, 2009 thanks guys (Y) Quote Link to comment https://forums.phpfreaks.com/topic/183155-how-do-i-make-a-string/#findComment-966655 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.