trinity Posted December 7, 2008 Share Posted December 7, 2008 1. How can I count the number of characters in a string, excluding spaces? Apart from counting the no. of spaces and and subtracting that from the total length of the string, is there not a simpler, neater way? 2. If I have a number of text files in a directory each with a URL in the filename, how can I easily extract the URLs out of the filenames and display a list of them? 3. This might be an easy one but I am a beginner and want a quick answer. I have a table of info consisting of a column of filenames, character count for that file, word count, then in the final cell of each row I want to have a link to a new page that will display the contents of the relevant file. How do I pass the string containing the file contents (which I have already created and saved to find out the length of it etc.) and pass it to the new page to display? Bearing in mind the link will have to pass different file contents depending on which row & file it corresponds to. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/135959-another-few-newbie-questions/ Share on other sites More sharing options...
msinternet Posted December 7, 2008 Share Posted December 7, 2008 Hi, 1) strlen(str_replace(' ','',$string)); Quote Link to comment https://forums.phpfreaks.com/topic/135959-another-few-newbie-questions/#findComment-708732 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 1. No, I do not think there is a neater way. You could create your own function such as: <?php function strlenNoSpace($string) { return strlen(str_replace(" ", "", $string)); } ?> Then just use that function to count without spaces. 2. I do not think it is wise to put a url in the filename, mainly because it can cause issues with files etc. But you would need scandir to get the files. 3. Use sessions, you can send the filename with session than read that file or use file_get_contents to display it. Quote Link to comment https://forums.phpfreaks.com/topic/135959-another-few-newbie-questions/#findComment-708734 Share on other sites More sharing options...
Mark Baker Posted December 7, 2008 Share Posted December 7, 2008 1. How can I count the number of characters in a string, excluding spaces? Apart from counting the no. of spaces and and subtracting that from the total length of the string, is there not a simpler, neater way? You can't. $length = strlen($string) - substr_count($string,' '); Quote Link to comment https://forums.phpfreaks.com/topic/135959-another-few-newbie-questions/#findComment-708735 Share on other sites More sharing options...
trinity Posted December 7, 2008 Author Share Posted December 7, 2008 Thanks for all the replies. 3. Use sessions, you can send the filename with session than read that file or use file_get_contents to display it. Thanks for this. But I want to pass a different filename to the new page depending on the link that is clicked on, how can I do this? (I really am a beginner with PHP you see!) Quote Link to comment https://forums.phpfreaks.com/topic/135959-another-few-newbie-questions/#findComment-708748 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 Use get data. The link would look like page.php?file=path/to/file/file.php Just be aware that that could be exploited to showing certain stuff you do not want shown. Quote Link to comment https://forums.phpfreaks.com/topic/135959-another-few-newbie-questions/#findComment-708751 Share on other sites More sharing options...
trinity Posted December 7, 2008 Author Share Posted December 7, 2008 for the link I have echo "<a href=\"page.php?file=path/filename">Click here</a>"; how do I add the correct filename ($filename) into where 'filename' is? Quote Link to comment https://forums.phpfreaks.com/topic/135959-another-few-newbie-questions/#findComment-708758 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.