View Full Version : Clip Variable

02-09-2010, 12:19 PM
Im using a PHP variable to define a span tag. However, the spaces in the php varaible seem to be causing problems with the span tag, so I was wondering if anyone can tell me a way to clip the variable down to the first 3 letters and use that.

For example, variable1=HELLO WORLD, variable2=HEL

Here is my HTML:

<a href="#" class="buttonx"><span class="<?php echo $_product->gettesting() ?>">This item is <?php echo $_product->gettesting() ?></span></a>

Can someone explain to me in idiot proof steps what I need to do?

02-09-2010, 12:20 PM

02-09-2010, 12:23 PM
Does this create a new variable, or remove characters from the same variable?

02-09-2010, 12:32 PM
Please read the friendly manual pages.

02-09-2010, 12:44 PM
it does both depending on what you want to use it for

$newvar = substr($oldvar, 0,3); // Creates a new variable $newvar and assigns it to that
$oldvar = substr($oldvar, 0,3); // Changes the old variable $oldvar to the three letters