Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/135959-another-few-newbie-questions/
Share on other sites

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.

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,' ');

 

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!)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.