if strlen()

Secţiune dedicată începatorilor.

Moderatori: Moderatori, Start Moderator

Dj_Andrew
PHPRomania Supporter
Mesaje: 20
Membru din: Lun Sep 06, 2010 12:46 pm
Localitate: Craiova

if strlen()

Mesajde Dj_Andrew » Joi Sep 16, 2010 12:59 pm

Salut,
Revin cu o problema careia nu reusesc sa ii dau de cap:

<?php
class Animal
{
var $name;

function set_name($text) {
if strlen($text<=10) {
$this->name=$text;
}
}

function get_name(){
return $this->name;
}
}

$lion=new Animal;
$lion->set_name("Leo");
echo "The name of the lion is\n", $lion->get_name(),".";

?>

Iar rezultatul apare cam asa:
Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\xampp\htdocs\lion.php on line 7



rudisoft
Average Member
Mesaje: 109
Membru din: Mar Feb 10, 2009 1:22 pm
Contact:

Mesajde rudisoft » Joi Sep 16, 2010 1:04 pm



[php]
<?php
if ( strlen($text<=10) ) {

}
?>
[/php]
Professional PSD/Image to XHTML/CSS services: | |

Avatar utilizator
mndrk
Senior Member
Mesaje: 271
Membru din: Mar Iun 22, 2010 12:02 pm
Localitate: Bucuresti
Contact:

Mesajde mndrk » Joi Sep 16, 2010 1:27 pm



Dj_Andrew
PHPRomania Supporter
Mesaje: 20
Membru din: Lun Sep 06, 2010 12:46 pm
Localitate: Craiova

Mesajde Dj_Andrew » Joi Sep 16, 2010 2:48 pm

Va multumesc!
Am ramas totusi cu o nedumerire:
Daca scriu "if (strlen($text)<=10) {" si schimb numele cu ceva mai mare de 10 caractere, atunci imi afiseaza numele .In schimb, daca pun "($text)>=10" atunci nu imi va mai afisa numele.
Totusi, nu ar trebui sa fie exact invers? adica 12<=10 (FALSE) deci "if (strlen($text)<=10) {" =FALSE si nu mai trebuie afisat nimic ?

Avatar utilizator
Sim Master
Average Member
Mesaje: 189
Membru din: Dum Aug 22, 2010 4:31 pm
Localitate: Timisoara
Contact:

Mesajde Sim Master » Joi Sep 16, 2010 3:06 pm

ciudat, pentru ca am testat si eu codul tau si afiseaza cum trebuie. daca puneam "Leo" zicea ca "The name of the lion is Leo" si daca puneam "Leooooooooooooo" zicea doar "The name of the lion is ."

HarryBrown
PHPRomania Supporter
Mesaje: 9
Membru din: Vin Sep 10, 2010 2:09 pm

Mesajde HarryBrown » Sâm Sep 18, 2010 12:52 pm

Probabil ai vreo greseala pe undeva, verifica mai bine.
Si eu ma lovesc uneori de niste "chestii" d-astea mici care imi iau ore sa pricep care e faza. De obicei de la oboseala.


Înapoi la “PHP Incepători”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 23 vizitatori