Does anyone have a PHP snippet of code for grabbing the first “sentence” in a string?

前端 未结 7 1180
刺人心
刺人心 2021-02-14 02:28

If I have a description like:

\"We prefer questions that can be answered, not just discussed. Provide details. Write clearly and simply.\"

7条回答
  •  悲&欢浪女
    2021-02-14 02:36

    Try this:

    $content = "My name is Younas. I live on the pakistan. My email is **fromyounas@gmail.com** and skype name is "**fromyounas**". I loved to work in **IOS development** and website development . ";
    
    $dot = ".";
    
    //find first dot position     
    
    $position = stripos ($content, $dot); 
    
    //if there's a dot in our soruce text do
    
    if($position) { 
    
        //prepare offset
    
        $offset = $position + 1; 
    
        //find second dot using offset
    
        $position2 = stripos ($content, $dot, $offset); 
    
        $result = substr($content, 0, $position2);
    
       //add a dot
    
       echo $result . '.'; 
    
    }
    

    Output is:

    My name is Younas. I live on the pakistan.

提交回复
热议问题