PHP Tutorials: Name Splitter (Part 1)
phpacademy asked:
Splits a full name into two seperate variables. Useful for signup forms where you just want to ask the user their full name, and not have two seperate boxes for first and last names. … php programming tutorial tutorials help name names split splitter seperate
Create a video blog
Caffeinated Content – Members-Only Content for WordPress
Oke, forgot to say that people will learn the purpose of a function. So in that way good tutorial.
Caffeinated Content – Members-Only Content for WordPress
You loop through all letters to discover a space. Not really efficient. On the other hand, like others said, explode is much less code.
If you do not want to create an array, you can also use ´strpos’ to get the position of the last space (or only space) in the string. If there are no spaces, it will return false. If it has, you then just simply can use mb_substr to split.
But 3 fields cannot be avoided. Firstname, middlename & lastname is I think not to much to ask.
PHP programming
Why don’t you try to start from the FIRST Class… ( Basics )
Caffeinated Content
I just realized below that you noted this was just for logic lesson. Guess I didn’t read the comments first. I think logic could still be explained a bit more easier.
Create a video blog
It would seem to me you could just take the $string = explode(” “, $name) to get an array, count the array out, and then you could assign each value. so if a person has ” James Tiberius Kirk ” as their name, you can effectively grab their middle name too. Make sure to trim the initial text of course. This is just my thoughts.
Caffeinated Content
How do you figure that? I’m pretty far in PHP and I know he is explaing everything about PHP the HTML he doesn’t need to explain you should know HTML before learning PHP.
Create a video blog…instantly.
You go to fast and don’t explain.
Horrible.
Caffeinated Content
I’ve explained this before, I’m basically teaching this for the purpose of getting your head around logic. I know the explode would be quicker, but you’d be learning a function and not know how it works!
PHP programming
DUDE??
Why So Long..
Just Use Explode And ForEach…
Lol
Caffeinated Content
Hmm, why bother using (mb_)substr for echoing the name. Just use: $fullname[$x].
Glad to see somebody else is doing PHP tutorials though
Caffeinated Content – Members-Only Content for WordPress
$lastname value is ” ” and not “Garret”
instead
$firstname is “AlexGarret”
I don’t understand the logic..
program is wrong in the logic.
Create a video blog
hii your r sow good in php
Caffeinated Content
True, even though I know all of this, it’s good practice to learn the language in every way.
Caffeinated Content
The point of this was to teach people the logic of string operation. Yes, someone can use split, but then then may not be very good at programing logic.
Kansieo.com
if you use split(); this will be fine ..