Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP remove all characters before specific string

Tags:

string

php

I need to remove all characters from any string before the occurrence of this inside the string:

"www/audio" 

Not sure how I can do this.

like image 918
user547794 Avatar asked Oct 18 '11 05:10

user547794


People also ask

How do I remove all characters before a specific character in PHP?

You can use strstr to do this. Show activity on this post. The explode is in fact a better answer, as the question was about removing the text before the string.

How do you remove portion of a string before a certain character in PHP?

substr() function: The substr() function is an inbuilt function in PHP is used to extract a specific part of string.

How to remove all characters from a string in PHP?

Using str_replace() Method: The str_replace() method is used to remove all the special characters from the given string str by replacing these characters with the white space (” “).


2 Answers

You can use strstr to do this.

echo strstr($str, 'www/audio'); 
like image 164
xdazz Avatar answered Sep 21 '22 13:09

xdazz


Considering

$string="We have www/audio path where the audio files are stored";  //Considering the string like this 

Either you can use

strstr($string, 'www/audio'); 

Or

$expStr=explode("www/audio",$string); $resultString="www/audio".$expStr[1]; 
like image 30
Wazy Avatar answered Sep 17 '22 13:09

Wazy