Forum

In string how do i wrap last word in span?

Tagged: 

This thread contains 2 replies, has 2 voices, and was last updated by Profile photo of rumourbazar2017 rumourbazar2017 3 months, 1 week ago.

  • Author Replies
  • #18257

    String : “Samsung mobile phones”

    Output : Samsung mobile <span>phones</span>


  • #18268

    <pre class=””lang-php”><span class=”pln”>$str </span><span class=”pun”>=</span> <span class=”str”>”</span>`<span class=””str””>Samsung mobile phones”</span><span class=””pun””>;</span>
    <span class=””com””>// Split it into pieces, with the delimiter being a space. This creates an array.</span><span class=””pln””>
    $split </span><span class=””pun””>=</span><span class=””pln””> explode</span><span class=””pun””>(</span><span class=””str””>” “</span><span class=””pun””>,</span><span class=””pln””> $str</span><span class=””pun””>);
    with this you can find last word .(ex</span><span class=””pun””><code><span class=””str””>phones</span>) than just replace with(<span</code></span><span class=””pun””><code><span class=””str””>>phones</span></code></span>). ) <span class="pun">str_replace("</span><span class="str">phones</span><span class="pun">“,”</span><span class="pun">phones“,”</span><span class="pun">Samsung mobile phones“);`</span>


    • #18280

      your problem just solve with explode and string replace.


You must be logged in to reply to this thread.

What's going on?
Members Currently Active: 0
No users are currently active
Members active within the past 24 hours: 1
student01

GET FREE CONSULTATION

Call Us Now For Free Consultation97370 05566

Our experts listen to you patiently and suggest you the right course after conducting a personality profile test. Register your interest below to schedule personality profile test for you.

SUBSCRIBE TO OUR NEWSLETTER

Contact Us

Working Hours

  • Monday9:00 AM – 9:00 PM
  • Tuesday9:00 AM – 9:00 PM
  • Wednesday9:00 AM – 9:00 PM
  • Thursday9:00 AM – 9:00 PM
  • Friday9:00 AM – 9:00 PM
  • Saturday9:00 AM – 9:00 PM
  • SundayClosed
Copyright 2017 Smart Mentors. All Rights Reserved.

Login

EXISTING MEMBER LOGIN

FORGOT PASSWORD

Sign up now to Become An Instructor

Register your Interest