SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question if php variable contains certain word echo this

    I have a php variable $colour.
    What I need to set up is a script that will check if the value of this variable contains certain data and if so will echo something.
    For example:
    $colour = 'Indigo Blue';
    I need to set up a statement that will check if the colour variable contains the word Blue anywhere and if so will echo the word "BLUE"

    Can anyone tell me how to code this please?

    Sorry if this is a really simple question that I am missing but I can't work this one out!

    Thanks for nay help in advance

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Here you go. See stripos for more.
    PHP Code:
    <?php
    $colour 
    'Indigo Blue';

    if(
    false !== stripos($colour'blue')){
      echo 
    'Blue';
    }
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

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