Is a loop required?

I am not sure how to complete the following:

Using your knowledge of ASCII character sets and If-Else, create a PHP application that will read through every character of a stored string, by a using a suitable loop, and will count the number of @ characters found in the string. (Note: the ASCII value for the @ character = 64). The number of @ characters found should be displayed on screen (even if none were found). To help you achieve this you may need to count the number of characters in the string.

says right there in the assignment, by a using a suitable loop

I won’t do anyone’s assignment, but i will help you out if you can provide some code. As a tip, to count the number of characters in a string, you can use strlen(), or count the number of times a character is used, use substr_count(). you’ll probably want to use a for loop or a do while loop too. Happy hunting :slight_smile:

there is a ton of misleading information in that assignment! you have to learn to problem solve things a bit, who cares about ascii and the number code for the @ symbol!!! In this assignment that is just extra info that is not needed to complete the assignment! Also you do NOT need to use loops to come up with an actual answer, but in this assignment it seems that they want you to use a loop, so LMAO yes to get a good grade you better find a good loop!
I am going to post an example of a loop through a string, it is not a copy and paste into your assignment you are going to have to use substr_count() in there somewhere but this will get you a good start in the right direction!

[php]$string = “this is a veeeeeerrrrry looooooooooooong string”;
$string_a = explode($string, " ");
for ($i=0; $i<count($string_a); $i++) {
$s = $string_a[$i];
if (strlen($s)<10) {
$string_a[$i] = “”;
}
}

$final_string = join($string_a, ’ '); [/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service