Need help with strstr()

Discussion in 'PHP' started by rob7676, Nov 11, 2009.

  1. #1
    OK, I've been at this for hours now and can't get it to do what I what. It may not even be the right function to do this with. I have a search on a site that searches the db for files and displays a link to the files returned. If a document is in pdf I want it to display a pdf icon and if in word to display a word icon. Here is where I'm at, can anyone help me?

    $name2 = $row['name'];
    								if (strlen(strstr($name2, '.pdf'))>0) {
    									$icon = "<img src='pdf_icon.png' width='25px' height='30px' border='0' />";
    								} elseif (strlen(strstr($name2,'.doc'))>0) {
    									$icon - "<img src='ms-word-icon.png' width='25px' height='30px' border='0' />";
    								} else {
    									$icon = "";
    								}
    								print "<td width='20px'>
    									   <a href='msds/" . $name2 . "' target='_blank'>" . $icon . "</a></td>
    									   <td>" . $name2."</td>
    									   <td>" . $row['number']."</td>
    									   <td>" . $row['manufacture']."</td>";
    								print "</tr>\n";
    Code (markup):

     
    rob7676, Nov 11, 2009 IP
  2. superdav42

    superdav42 Active Member

    Messages:
    125
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Looks like the problem is at line 5:
    $icon - "<img src='ms-word-icon.png' width='25px' height='30px' border='0' />";
    PHP:
    the '-' should be a '='

    also you don't need to do the strlen check strstr will return false if it is not found.
     
    superdav42, Nov 11, 2009 IP
    rob7676 likes this.
  3. rob7676

    rob7676 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can't believe I missed that, guess I needed another set of eyes to look. I figured I messed up the if statements, never done anything with that function before. Thanks
     
    rob7676, Nov 11, 2009 IP