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 trial

PHP PHP Functions PHP Internal Functions PHP String Functions

Seth Warner
Seth Warner
5,348 Points

Im just using my imagination here but could you do the following since php reads up to down?

would this run?

$quote = "The dog ran";

$leng = strlen($quote):

$leng = $value

substr($value(0, 11));

echo $value

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

I don't know what you are trying to do but did you declare $value somewhere else before you assigned it to $leng? If not that will most likely throw an error because you are trying to assign a variable that hasn't been declared.

3 Answers

Hi Seth,

I'm unsure of what you are wanting to do, but here is what I think you were trying to do. It looks like you were trying to pass the $quote variable to $leng to get the length of the string. Then set $value = to Length and run them both through the substr function.

Check out the code example I did below. I think it should help.

//Set the quote variable 
$quote = "The dog ran";

//I am getting the length of the $quote variable here.(returns 11)
$leng = strlen($quote);

//Running the quote variable through the substr function starting at position 0 then going to the full length of the variable which is set by the $leng variable. 
$value = substr($quote, 0, $leng); 

echo $value;

I hope this helps. Please let me know if you have any questions.

Codin - Codesmite
Codin - Codesmite
8,600 Points

This code will throw an error as you haven't declared a value for $value, unless you have declared value prior to this code?

Ed Everett
Ed Everett
1,566 Points

$value has been declared as the variable $leng higher up the code.

<?php

$quote = "The dog ran";

$leng = strlen($quote);

$value = $leng;

echo substr($value,0, 11);
echo "<br>";
echo $value;

?>

You typed little bit wrong in PHP, I guess that you were a bit hurry :smile: :sweat: when you call substr it will return 11 and when you call value it will also return 11

Btw. PHP doesn't read up to down but I think I understand what you mean :smile:

let me know if I have missunderstood :)