Page 1 of 5 123 ... Last
  • Jump to page:
    #1
  1. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Wow!! So cool... !



    This is very good.

    I was thinking of doing myself some sort of automation, because it is a pain keeping track and updating rollover images, and I was looking at PHP as a possible tool.

    This article is very well written and saved saved me a lot of work. In a matter of 1-2 hours I had it working, with minimal knowledge of PHP!

    Liviu

    PS: keep posting tricks like this!! ;-)
  2. #2
  3. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    split()


    I've been trying to make the initial part work where the page name is obtained from the page path environment variable. The system is Apache on Linux, PHP 307
    <br>
    <br>
    The SCRIPT_NAME initially stored in $page is: /TEST/index.phtml
    <br>
    <br>
    I can get as far as grabbing the string "index.phtml" by doing a split() on the "/".
    <br>
    <br>
    I added a dot to the string so that it became: .index.phtml
    <br>
    and proceeded to try split() it on the ".".
    <br>
    <br>
    But it doesn't work! The first two elements of the resulting array are empty, and the third element contains just "ndex.phtml" (what happened to the "i"?)
  4. #3
  5. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: split()


    Hmmm... good question.
    <br>
    <br>
    Everything you're doing seems to be right, including adding the extra "." at the beginning of the string prior to SPLITting the "."'s.
    <br>
    <br>
    Is there any way you can send me the soruce code of the page you are working on? A bug may have creeped in there somewhere else.
    <br>
    <br>
    You can also try changing the SPLIT by reducing the number of elements that are SPLIT out of obth the directory call (/) and the file name call (.). Ech system, and directory heirarchy requires differnet numbers, and only experimentation will find your compbination.
    <br>
    <br>
    For instance, on ZEUS, my production machine, my directories are nested deeper (by 3 or 4 levels) than they are on the server, so the SPLITs might be as high as 6 or 7 on ZEUS, but only 3 or 4 on the server.
    <br>
    <br>
    I'll write a bit of debug code that ight help you find out what's going on. I'll try to post it this weekend.
    <br>
    <br>
    -- Chris
    <br>
  6. #4
  7. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    $page


    Hello..

    I am having trouble with the first part where it tries to figure out the page name, mainly having trouble with the directory depth stuff. is the second number in regards to dir depth always one less than the first?
    if so i would assume i could start with 1 and 0 and work my way up otherwise it seems like a lot of guessing.. also, does directory depth mean from the document root or from the actual root of the machine?.
    I have the example pages located at http://dopefiend.org/php/dynamic_menu/
    so i would guess that is 2 directories deep
    but the full path is for example
    /dir1/dir2/dopefiend/php/dynamic_menu/

    help please!

    DaveMeiners
    dave@itsdave.com
    http://itsdave.com
  8. #5
  9. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: split()


    I'm having the same problem also. I think it has to do with the interpreter using the dot as a wildcard. Here\s the code:

    <!-- Code -->
    <p><pre><font color=#000000><xmp>
    echo "Testing / splitting<br>";
    $page = $PHP_SELF ;
    echo "Page String: $page<p>";
    $page = split ("/", $page, 3);
    echo "First Element: $page[1]<BR>";
    echo "Second Element: $page[2]<P>";

    echo "Testing . splitting<BR>";
    $test = $page[2];
    $page = "." . $page[2];
    echo "dot page: $page<BR>";
    $page = split (".", $page, 3);
    echo "First Element: $page[1]<BR>";
    echo "Second Element: $page[2]<BR>";
    $page = $page[1];
    echo "final page: $page<P>";

    echo "Testing . strpos<BR>";
    $pos = strpos ($test, ".");
    $test = substr ($test, 0, strpos($test, "."));
    echo "test: $test<BR> pos: $pos";
    </xmp></font></pre><p>
    <!-- Code -->

    The results look like this:
    Testing / splitting
    Page String: /dynmenu/test.php3
    First Element: dynmenu
    Second Element: test.php3
    Testing . splitting
    dot page: .test.php3
    First Element:
    Second Element: est.php3
    final page:

    Testing . strpos
    test: test
    pos: 4
    ===================================
    I have provided a work around using strpos and substr, but I am curious about the strip results. Any insights?
  10. #6
  11. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: split()


    Here is another way to get just the current page name without any file extensions, without using split at all. It has the advantage of not caring how deep your directories are:

    <!-- Code -->
    <p><pre><font color=#000000><xmp>
    echo "Testing / strrpos<BR>";
    $page = $PHP_SELF ;
    echo "Page String: $page<br>";
    // Find the last occurence of the / character
    $pos = strrpos ($page, "/");
    echo "last / pos: $pos<BR>";
    // Grab ererything past the last /
    $page = substr ($page, strrpos($page, "/") + 1);
    echo "page: $page<BR> pos: $pos<P>";

    echo "Testing . strpos<BR>";
    $pos = strpos ($page, ".");
    echo "First . pos: $pos<BR>";
    // Grab from the beginning of the string up to the . char
    $page = substr ($page, 0, strpos($page, "."));
    echo "Final page: $page<BR>";
    </xmp></font></pre><p>
    <!-- Code -->

  12. #7
  13. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: split()


    thanks for your post the line

    <!-- Code -->
    <p><pre><font color=#000000><xmp>
    $test = substr ($test, 0, strpos($test, "."));
    </xmp></font></pre><p>
    <!-- Code -->

    really helped me

    now my page works :)
  14. #8
  15. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Similar try


    We are also trying to do something similar on http://www.inetindia.com/travel
    We are facing problem with the random advertising banner cgi script - the regular include / exec cgi include does not seem to work with php3 -
    Any comments?

    has anyone tried a random banner program in php3?


    Would appreciate any help we can get
  16. #9
  17. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: split()


    Yes, thanks for the workarround. im new to php3 and ive been banging by head on the wall for some time now... ive included my source, it isint pretty but i know it works.. so for those of you stuck in my position this will proably help..

    Replace the old code w/this one to get $page to be correct:

    <!-- Code -->
    <p><pre><font color=#000000><xmp>
    <?
    $findpage = $PHP_SELF ;
    $findpage = split ("/", $findpage, 3);

    $test = $findpage[1];
    $findpage = "." . $findpage[2];
    $findpage = split (".", $findpage, 3);
    $findpage = $findpage[1];

    $pos = strpos ($test, ".");
    $test = substr ($test, 0, strpos($test, "."));
    $page = $test;
    ?>
    </xmp></font></pre><p>
    <!-- Code -->

    change the array varriables arround to suit your needs.

    Thx again..
    Da Almighty Nayr

  18. #10
  19. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: Similar try


    Yes others have tried random banner programs, i know there is one at this URL:
    http://phpbuilder.px.sklar.com/section.html?section_id=9

    their main website is located at: www.phpbuilder.com/

    -Da Almighty Nayr
  20. #11
  21. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: split()


    Mark,
    <br>
    <br>
    That's a great bit of code. Thanks. It works great on my old server configuration (PWS 4.0).
    <br>
    <br>
    Unfortunately, Apache on Windows 95 (which I'm running now on my development machines)requires PHP to be run as a CGI rather than a module, and that causes PHP_SELF to be PHP.EXE regardless of the script name. I hear rumors of an Apache for Windows distribution with a PHP module, so this may change in the immediate future (I hope).
    <br>
    <br>
    Also, you may wonder why I have such a convoluted way of getting the page name when your method is so elegant...
    <br>
    <br>
    ...Well, in some of the sites I've developed, I also needed to know which subdirectory the page was in, and that was the quickest way I could do it across both the development machine and the server. (There were other methods but they broke on one or the other due to environment variable incompatibilities.) So I just adapted the technique for the article and tried to keep it as generic as possible.
    <br>
    <br>
    PHP runs gret across platforms, but, alas, different servers give different results, so there will always have to be workarounds for scripts like this.
    <br>
    <br>
    -- Chris
  22. #12
  23. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: split()


    Or a shorter one :)

    <!-- Code -->
    <p><pre><font color=#000000><xmp>
    $page = ereg_replace(".*/","",$PHP_SELF);
    $page = split( "\.", $page, 2);
    $page = $page[0];
    </xmp></font></pre><p>
    <!-- Code -->

  24. #13
  25. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: split()


    Chris Lott, IT Specialist at University of Alaska, offered me this solution: "I think the problem you are having is that in the last split statement, you are splitting on the "." character, which actually has a different meaning in a regex statement. This code works for me:"<p>$page = $PHP_SELF;<p>//print to check # of levels<br>print "$page&lt;br>";<br>$page = explode("/", $page);<p>//adjust numbers of indices per<br>//previous print statement<br>print "$page[1] and $page[2] and $page[3]&lt;BR>";<p>//notice escape character in the split<br>$page = split("\\.", $page[3], 2);<br>print "$page[0]";<p>Chris's solution also makes it easy enough to capture sub-directories if needed.
  26. #14
  27. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: split()


    > Chris's solution also makes it easy enough to capture sub-directories if needed.
    <br>
    <br>
    Actually, Robert, the code was a snippet taken from my personal code library, and modified specifically for the article. It was originally intended to determine not only the page, but the subdirectory of the calling page.
    <br>
    <br>
    I have received a fair amount of email on the subject, and have although there are specific reasons I did it the way I did when I did it, I recently changed server software on my development machine to Apache. Since Apache runs PHP as a CGI and not a module on Win 95 machines, some environmental variables broke, requiring a change in the code and the variable used.
    <br>
    <br>
    The new version is a slightly modified version of the code posted by Mark Swiatek in his message of 06-07-1999. His code should work without modification on more platforms than mine.
    <br>
    <br>
    <br>
  28. #15
  29. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Tiering


    Got the exapmle running this morning; and I'm thrilled. The next step for me is to figure out how to tier my site. At one point I had fifty-odd pages; I certainly won't want a flat structure and fifty-odd buttons on a page!
    <br>
    <br>
    I'm thinking the first stab (after sketching out the tier struture) will be to change pages.html so it has a separate array for each "node"; then all I have to do is change template.html for each node to include the proper array. Basically, in page four of the article, where we get php additions to the javascript, I'd substitute "$node_n_pages" for "$site_pages". That should do the trick, shouldn't it?
Page 1 of 5 123 ... Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo