Asked  7 Months ago    Answers:  5   Viewed   40 times
$string = "Hello World Again".
echo strrchr($string , ' '); // Gets ' Again'

Now I want to get "Hello World" from the $string [The substring before the last occurrence of a space ' ' ]. How do I get it??



This is kind of a cheap way to do it, but you could split, pop, and then join to get it done:

$string = 'Hello World Again';
$string = explode(' ', $string);
$string = implode(' ', $string);
Wednesday, March 31, 2021
answered 7 Months ago

You should use the tool that is designed for this type of job, parse_url



$urls = array('',

function clean_url($url) {
    $parts = parse_url($url);
    return $parts['scheme'] . '://' . $parts['host'] . $parts['path'];

foreach ($urls as $url) {
    echo clean_url($url) . "n";


ยท> php url.php                                                                                        
Wednesday, March 31, 2021
answered 7 Months ago

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario:

Related usability ticket:

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
answered 7 Months ago

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
answered 5 Months ago

You probably want something like /(.*?):(.*)/. The ? after the * will make it "non-greedy", so it will consume as little text as possible that way. I think that will work for your situation. By default, * is "greedy", and tries to match as many repetitions as it can.

Edit: See here for more about matching repetition using the * and + operators.

Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :