Jump to content

[SOLVED] Displaying the first four characters in php.


Andrew R

Recommended Posts

That won't work, since the quotes characters are wrong. You should be using normal single quotes ' not "smart" quotes ‘’

 

Also if the first string is longer than 4 characters, a better way would be to use the explode() function:

<?php
$tmp = explode('_',$row['name']);
echo $tmp[0];
?>

 

Ken

I just re-read your post... are you saying you always want to display the part before the _ ? No matter what the length?

 

Yeah most names in the database are four characters long but some are longer so I want to display everything before the _. 

 

How would have add something that this into the above code

$names = addslashes($riga[2]);

instead of the

<? echo $row_users[‘name’]; ?>

 

Thanks for the help.

Sorry to bring this topic up again but how would I display everything after the _ if the name was Robb_Bob how would I display Bob.

 

Thanks for your help.

$var = "Robb_Bob";
$x = explode("_",$var);
echo $x[1];
//use print_r to display everything in the array, so you can see what explode does
//print_r($x);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.