Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts

    highlight a word in php

    I want to highlight a word if for e,g i have apples in the description.

    How can i do that in php
    Please de-reputate me
    0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Specify .highlight { background: yellow; } in CSS, then you may do the following:
    PHP Code:
    $text str_replace'apples''<span class="highlight">apples</span>'$text ); 
    Look into the use of arrays, and maybe even preg_replace(), to expand upon this example.
    Last edited by kbluhm; 07-18-2008 at 07:01 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •