if pathname query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fructose
    New Member
    • Sep 2006
    • 8

    if pathname query

    Hi all,

    I'm trying to find a command that will echo a string IF the filename starts with an underscore. Effectively, I'm looking for a wildcard symbol.

    I'm imagining something like the following:
    (the 'class' commands are accessing CSS)


    <?php

    $big_warp_graph ic = "<td class=\"warp-big\">";
    $warp_graphic = "<td class=\"warp\"> ";
    $no_warp_graphi c = "<td">";

    if ($page == "blah blah - News"
    or $page == "blah blah - Glossary")
    {echo $warp_graphic;}
    elseif ($filename == "_*")
    {echo $big_warp_graph ic;}
    else
    {echo $no_warp_graphi c;}

    ?>

    I'm sure the "filename" command and the asterisk are wrong, but please could someone tell me what they should be.

    For clarity, this is what I'm trying to do, and why:

    I have 50-odd php pages that contain individual definitions from a glossary.

    I originally placed them all in a "glossary/..." folder, but decided against it as the php inserts and images I was trying to access from the glossary entries were not being found after the directory was changed. It would also be a lot of work to adjust all the relevant paths.

    My idea is to rename each glossary entry page with an underscore at the start (a random choice, but something that would distinguish them all as being glossary entries, avoiding confusion with the other files). I will then keep them in the main folder. I was hoping that some sort of wildcard function might exist.

    As you will have gathered from the code above, my reaon for doing this in the first place is that I want a different graphic on all glossary entries, but also want the freedom to change my mind later with having to open up hundreds of files to edit.

    Given my ramble, could anyone suggest eiher a solution to what I had in mind, or - even better - the 'right' way of going about this?

    Thanks a lot,

    fructose
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Use the substring function
    Code:
    elseif (substr($filename,0,1) == "_")
    Ronald :cool:

    Comment

    • fructose
      New Member
      • Sep 2006
      • 8

      #3
      Thanks.

      But what does the 0,1 mean?

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        substr(string string, int start position, int length)

        Ronald :cool:

        Comment

        • tbb9216
          New Member
          • Sep 2006
          • 16

          #5
          substr ( string, start point, end point )

          where the first available start point is 0.
          so that means:

          [PHP]
          echo substr('hello', 0, 1);
          // echos h
          echo substr('hello', 1, 1);
          // echos e
          echo substr('hello', 0, 3);
          // echos hel
          echo substr('hello', 1, 3);
          // echos ell
          [/PHP]

          for the EXACT info, check out http://php.net/substr

          Comment

          • fructose
            New Member
            • Sep 2006
            • 8

            #6
            Thanks a lot guys - very helpful.

            Comment

            Working...