Is This Even Possible?

Discussion in 'PHP' started by scottlpool2003, Jun 11, 2009.

  1. #1
    Okay so I use PHP to replace titles, keywords and descriptions on my website:

    $title = "Watch " . $var . " Full Movie Online Free";
    $keywords = "Watch " . $var . " Free, Watch " . $var . " movies, watch " . $var . " movies, free online movies, watch free movies, ";
    $description = "Watch " . $var . " Free";
    PHP:
    That's the code to replace the keywords in my header, which I PHP include.

    The problem is that sometimes users search e.g. Watch Up Free

    This will then put Watch Watch Up Free Free because I'm already declaring "Watch" and "Free"

    So I tried writing a bit of code:

    if {
    (!strpos($description, "watch")) 
    }
    then
    {
    $description = "" . $title . "";
    }
    else
    {
    ($description = ("Watch " . $title . " Free" )
    
    }
    
    PHP:
    But I'm just getting errors. Is it possible to check if "Watch" and "Free" exist within the string and use an ELSE statement add jut " . $title . " instead of Watch " . $title . " Free

    Or am I just wasting my time? The only reason I want to sort this is because Google are indexing these pages.
     
    scottlpool2003, Jun 11, 2009 IP
  2. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i don't understand the full post but yes you can check if certain keyword exists and use else statement.

    $keycheck = (bool) strstr("$description", "watch");

    it will return 1 when it finds watch in $description.

    if($keycheck ==1){
    statement for true
    }else
    {
    }
     
    mdrobiul, Jun 11, 2009 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    Thanks for your reply. I've since edited my sloppy code and come up with:

    if (!strpos($description, "watch " . $var . " free")) 
    {
    $description = "" . $var . "";
    }
    
    else
    {
    $description = "Watch " . $var . " Free";
    
    }
    PHP:
    It just needs organizing but I'm not the biggest PHP person so I'm completely clueless from here on, anyway you can edit this for me? $var is the searched item.
     
    scottlpool2003, Jun 11, 2009 IP
  4. renzmar

    renzmar Peon

    Messages:
    308
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try this one:

    //Just add the words you want to removed from $var
    $remove = array("Watch", "up", "Free");

    //This should convert all the words you added from $remove to empty string
    $newvar = str_replace($remove, "", $var);

    //You can now use your previous code but use $newvar instead
    $title = "Watch " . $newvar . " Full Movie Online Free";
    $keywords = "Watch " . $newvar . " Free, Watch " . $newvar . " movies, watch " . $newvar . " movies, free online movies, watch free movies, ";
    $description = "Watch " . $newvar . " Free";

    I hope it helps.. Goodluck.. ;)
     
    renzmar, Jun 11, 2009 IP