heminfotech Posted March 13, 2007 Share Posted March 13, 2007 Hi I want to concate one string for the file writting how to fill spaces for the not available values please any one can help me Thanks For ur support Regards Hemal Jivani Quote Link to comment https://forums.phpfreaks.com/topic/42487-solved-ho-to-add-fillers-in-php-string/ Share on other sites More sharing options...
monk.e.boy Posted March 13, 2007 Share Posted March 13, 2007 $s = $var1.','.$var2; This concatenates two variables. Also check out the isset function: http://uk.php.net/manual/en/function.isset.php monk.e.boy Quote Link to comment https://forums.phpfreaks.com/topic/42487-solved-ho-to-add-fillers-in-php-string/#findComment-206136 Share on other sites More sharing options...
heminfotech Posted March 13, 2007 Author Share Posted March 13, 2007 sorry I think u didnt get me on this. say I have a string of 100 character first 10 characters are filled as one variable. var1="abcdefghij" var2="asdf5" now I want to fill the spaces of 85 spaces as I have to concate this string as on line of record. so var1 stands first then the var2 comes as last values. so I need filler code if u have or any idea how to do it? Thanks for u support Quote Link to comment https://forums.phpfreaks.com/topic/42487-solved-ho-to-add-fillers-in-php-string/#findComment-206143 Share on other sites More sharing options...
kenrbnsn Posted March 13, 2007 Share Posted March 13, 2007 If you are writing these variables to a file, I would use the sprintf() function to format the string: <?php $var1="abcdefghij"; $var2="asdf5"; $record = sprintf("%-95s%5s",$var1,$var2); echo strlen($record).'<br>'; //debug line echo '<pre>' . $record . '</pre>'; //debug line ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/42487-solved-ho-to-add-fillers-in-php-string/#findComment-206155 Share on other sites More sharing options...
billskipton Posted March 13, 2007 Share Posted March 13, 2007 Sprintf is the way to go for writing to a file, or prinf for a variable (eg $fred = printf ('.....',......)). It's complicated, so best ask google for PHP PRINTF Best of luck Bill. Quote Link to comment https://forums.phpfreaks.com/topic/42487-solved-ho-to-add-fillers-in-php-string/#findComment-206212 Share on other sites More sharing options...
kenrbnsn Posted March 13, 2007 Share Posted March 13, 2007 The sprintf() and printf() functions use the same mechanism to format a string. This is all explained fairly well in the online manual. Ken Quote Link to comment https://forums.phpfreaks.com/topic/42487-solved-ho-to-add-fillers-in-php-string/#findComment-206238 Share on other sites More sharing options...
heminfotech Posted March 13, 2007 Author Share Posted March 13, 2007 Thanks for all your support it helped me a lot to solve my problem. Quote Link to comment https://forums.phpfreaks.com/topic/42487-solved-ho-to-add-fillers-in-php-string/#findComment-206243 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.