Excluding Part of a Variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bbeavis123
Forum Newbie
Posts: 2
Joined: Wed Sep 10, 2003 11:56 am

Excluding Part of a Variable

Post by bbeavis123 »

I am using this to create a link to a php page:

zenoview.php?m=<?php echo $m; ?>&c=<?php echo $c; ?>

Next I want to add to the M variable in order to call a different set of images and text (see where I have added the _mt) :

zenoview.php?m=<?php echo $m; ?>_mt&c=<?php echo $c; ?>

This adds _mt to the M (model # variable) which in turn calls the existing variable with _mt added to it.

Now I need to figure out how to subtract that _mt addition on the next page using the same echo function since now the echo $m being used on that page will now be including the _mt within it.

In short, how do I subtract or exclude a portion of a variable?
Example...if m=123456_x and i want to use the function above to call it without the _x at the end.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

$var = substr($var,0,-2);
will remove the last 2 character of a varaible
bbeavis123
Forum Newbie
Posts: 2
Joined: Wed Sep 10, 2003 11:56 am

Post by bbeavis123 »

Thanks!

This works perfectly.
Post Reply