Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonah Shi
10,140 PointsQuestion about the course "Extending Object-Oriented PHP"
Just want to ask here for this function what if http:// is https://?
public function setWebsite($value) { $value = trim(filter_var($value, FILTER_SANITIZE_STRING)); if (empty($value)) { $this->website = null; return; } if (substr($value, 0, 4) != 'http') { $value = 'http://' . $value; } $this->website = $value; }
1 Answer
Niki Molnar
25,698 PointsHi Jonah
The function includes:
if (substr($value, 0, 4) != 'http') {
// If the first 4 characters of $value ARE NOT EQUAL TO http then...
}
Let's say the $value is "https://www.teamtreehouse.com"
What the substr() function is looking at is the first 4 characters of $value. Therefore it doesn't matter whether it's http or https - the first 4 characters are "http" in either case.
Hope that helps!
Niki