Modules 6 & 7: PHP Functions and Strings
Link to my site: http://drew-williams.infinityfree.me/Module7.php
For these modules, I created a short PHP page that demonstrates both a custom function and a few string operations. I’ve used PHP before, but it was nice to revisit the basics and set something up from scratch on a hosted server.
The function I wrote is called greet(). It takes a first and last name, combines them into a full name, and returns a greeting in uppercase. It’s simple, but it covers the main points from the assignment: parameters, concatenation, returning a value, and using a built-in string function (strtoupper()). Here’s the part I like about PHP, even though it’s an older language, it’s still extremely direct when you just want to manipulate text and send a response to the browser.
For the strings part, I included a few examples using built-in PHP functions:
- strlen() to count the number of characters in a sentence,
- str_word_count() to count the words, and
- strpos() to locate a specific word in the string.
Together, these examples show how PHP can handle string operations easily while running directly on the server.
In my view, functions and strings go hand in hand in PHP, functions let you package logic that manipulates text, while string functions give you control over the exact data you’re returning. It’s the same pattern I use in JavaScript or backend Node work, just in a different syntax.
Nothing here was particularly difficult, but I did have to remember that PHP uses . for concatenation instead of +. Once I got back into that mindset, everything flowed naturally. I saved the file as .php, uploaded it to my InfinityFree server, and it ran exactly as expected when I hit the page in my browser.
Overall, this was a quick refresher on server-side scripting, a reminder of how straightforward PHP can be when you just need to process data and render dynamic text. It was good to get it running live and see the difference between local execution and how the server actually parses and serves the output.
Comments
Post a Comment