在PHP中,如何在特定单词后面执行子字符串? [关闭]

I have a string like this:

Title December 15, 2016/0 Comments/topic/by joe blow Facebook Twitter Google+ LinkedIn My really important content that I want to display. I don't care about the title and social media words.

I'd like to strip the string to show everything after the word "LinkedIn ".

You can do so using the explode function provided by php

$str = "December 15, 2016/0 Comments/topic/by joe blow Facebook Twitter Google+ LinkedIn My really important content that I want to display";
$arr = explode("LinkedIn", $str);
echo(trim($arr[1]));

Output

My really important content that I want to display

You can use strstr it will start the string from which word or letter you want.

$str = "December 15, 2016/0 Comments/topic/by joe blow Facebook Twitter Google+ LinkedIn My really important content that I want to display";

        $str= strstr($str, 'LinkedIn');
        $str = trim($str,'LinkedIn');
        echo $str;

Here is my code :

$string = 'Title December 15, 2016/0 Comments/topic/by joe blow Facebook Twitter Google+ LinkedIn My really important content that I want to display';
$result = trim(substr($string, strpos($string, 'LinkedIn') + strlen('LinkedIn'))); 
echo $result;

I hope this will help your requirement.

substr will return a part of string

strpos will Find the position of the first occurrence of a substring in a string

strlen will get length of string

try this;

$str = "Title December 15, 2016/0 Comments/topic/by joe blow Facebook Twitter Google+ LinkedIn My really important content that I want to display. I don't care about the title and social media words.";
$needle = "LinkedIn";
$pos = strpos ($str, $needle);
$substr = trim(substr($str,$pos + strlen($needle)));

You can do it with strpos , strlen and substr !!

$str = "December 15, 2016/0 Comments/topic/by joe blow Facebook Twitter Google+ LinkedIn My really important content that I want to display";
$index = strpos($str, "LinkedIn"); // find from witch character "LinkedIn" starts
$index += strlen("LinkedIn"); // add "linked in length to $index"
$res = substr($str, $index);  // separate that number of characters from your string
echo $res;