aximbigfan Posted September 30, 2008 Share Posted September 30, 2008 Hi, Let's say I have this variable $vari = '/1/2/3/'; Now, I have this string: $otherstr = '/1/2/3/4/break/1/2/3/'; Basically what I need to do is get rid of $vari in the BEGINNING on $otherstr. Is there anyway to do this? Thanks, Chris Link to comment https://forums.phpfreaks.com/topic/126377-remove-a-full-string-from-the-beginning-of-a-string/ Share on other sites More sharing options...
hamza Posted September 30, 2008 Share Posted September 30, 2008 $otherstr is static or dynamic. mean every time it created with the same name if you answer is yes then you should use the code is below <?php $str ="$otherstr = '/1/2/3/4/break/1/2/3/'"; echo str_replace("$otherstr =","",$str); ?> this code will show you the /1/2/3/4/break/1/2/3/ only Link to comment https://forums.phpfreaks.com/topic/126377-remove-a-full-string-from-the-beginning-of-a-string/#findComment-653536 Share on other sites More sharing options...
discomatt Posted September 30, 2008 Share Posted September 30, 2008 <pre><?php $vari = '/1/2/3/'; $otherstr = '/1/2/3/4/break/1/2/3/'; if( strpos($otherstr, $vari) === 0 ) $otherstr = substr( $otherstr, strlen($vari) ); echo $otherstr; ?></pre> Link to comment https://forums.phpfreaks.com/topic/126377-remove-a-full-string-from-the-beginning-of-a-string/#findComment-653537 Share on other sites More sharing options...
aximbigfan Posted September 30, 2008 Author Share Posted September 30, 2008 Hi Guys, Got it working, thanks! Chris Link to comment https://forums.phpfreaks.com/topic/126377-remove-a-full-string-from-the-beginning-of-a-string/#findComment-653543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.