harishkumar09 Posted May 1, 2008 Share Posted May 1, 2008 How to convert a number to a string ? I want to create a new string by concatenating a string and a number.How to do it ? The scenario is the user selects the gallery he wishes to see.And I construct the filename which contains links to images by concatenating a standard string "file" and the number he has chosen say "4" to create "file4.txt" and assign it to a variable $myfile and then open the relevant file and then display the list of images contained in it. Can anybody help ? Quote Link to comment https://forums.phpfreaks.com/topic/103707-solved-converting-number-to-string/ Share on other sites More sharing options...
RichardRotterdam Posted May 1, 2008 Share Posted May 1, 2008 just typecast it $yourNumber=999; $numberInString=(string)$yourNumber; Quote Link to comment https://forums.phpfreaks.com/topic/103707-solved-converting-number-to-string/#findComment-530961 Share on other sites More sharing options...
harishkumar09 Posted May 1, 2008 Author Share Posted May 1, 2008 just typecast it $yourNumber=999; $numberInString=(string)$yourNumber; Thank you.But I didnt know there were variable types in PHP. I tried just concatenating a string variable and interger variable and assigned it to a string and it accepted it and was successful. I could do what I wanted. But thanks anyway. Quote Link to comment https://forums.phpfreaks.com/topic/103707-solved-converting-number-to-string/#findComment-530964 Share on other sites More sharing options...
discomatt Posted May 1, 2008 Share Posted May 1, 2008 Yes, PHP is very loose with variable types. Typecasting can come in handy, but for the most part it isn't necessary. Quote Link to comment https://forums.phpfreaks.com/topic/103707-solved-converting-number-to-string/#findComment-530983 Share on other sites More sharing options...
rhodesa Posted May 1, 2008 Share Posted May 1, 2008 You really don't need typecasting for this. Just put the number in the concatenation... <?php $n = 4; $myFile = 'file'.$n.'.txt'; //or $myFile = "file{$n}.txt"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/103707-solved-converting-number-to-string/#findComment-530993 Share on other sites More sharing options...
harishkumar09 Posted May 2, 2008 Author Share Posted May 2, 2008 Thanks Rhodesa. Thats what I did. You really don't need typecasting for this. Just put the number in the concatenation... <?php $n = 4; $myFile = 'file'.$n.'.txt'; //or $myFile = "file{$n}.txt"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/103707-solved-converting-number-to-string/#findComment-531518 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.