SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member Merlin Unknown's Avatar
    Join Date
    Jul 2003
    Location
    CyberSpace
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post VBScript to PHP - Syntax Highlighter

    I have written a Visual Basic syntax highlighter for my web site in VBScript. I pretty much just started out in PHP and now I would like to remake the code in PHP. Basically what I need to know is this:

    Equivalents for the following VB functions:

    1) Instr
    2) Replace

    Instr just tells you the first position of a string within another string. For example:
    InStr 1, "ThisIsATest", "Is"
    would return 5 because the first instance of "Is" is 5 characters away from the beginning.

    Replace merely replaces something within a string. For example:
    Replace "ThisIsATest", "Test", ""
    would return "ThisIsA" because it replaces the word "Test" with "" (null).

    If you have any idea of a PHP equivalent to these functions, I would very much like to know what they are.

    TIA,
    - Merlin Unknown

  2. #2
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    strpos() and str_replace(), respectively. You may also want to look at the tokenizer extension, if you're interested in trying a different approach.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  3. #3
    SitePoint Member Merlin Unknown's Avatar
    Join Date
    Jul 2003
    Location
    CyberSpace
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have looked at some information about the tokenizer extension, but it was kind of confusing. Would anyone mind giving a short explanation and/or an example? Thanks...

  4. #4
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's what the Zend Engine uses internally to parse PHP, so it's easily adaptable into a syntax colorer. What it does (to oversimplify quite a bit) is break input to it into the various "tokens" that make up a script, like "variable", "function", etc.,

    Try calling token_get_all() with a PHP script as it's argument, and print_r() the results.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  5. #5
    SitePoint Member Merlin Unknown's Avatar
    Join Date
    Jul 2003
    Location
    CyberSpace
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright...I got it to work. Thanks for the help anode!

    - Merlin Unknown


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
  •