SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: ASP to PHP?

  1. #1
    SitePoint Addict molder101's Avatar
    Join Date
    Apr 2004
    Location
    dorothy
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP to PHP?

    Hi,
    I am a PHP coder and do not know much about ASP. I was hoping one of the smarter individuals out there would be able to help me out with regards to the following code. I have tried several "automatic" ASP->PHP solutions, none of which have worked....

    Thanks in advance,
    Mike

    CODE///////////////////////////////////////////////////////////////////////////////

    function convert2Xhtml(theHtml)
    {
    var html;
    html = theHtml;

    // Make xhtml compatible
    html = html.replace(/<.*>?>/g,function(m,p,s){return m.replace(/\s(\w+=)([#\w,;]+)/g,function(m,p,s){return ' ' + p.toLowerCase() + '"' + s + '"';});});
    html = html.replace(/<(\/?\w+)([^>]*>)/g,function(m,p,s){return '<' + p.toLowerCase() + s;});
    html = html.replace(/<(meta|base|basefont|param|link|img|br|hr|area|input)([^>]*)>/g,function(m,p,s){return m.indexOf(' />') == -1 ? '<' + p + s + ' />' : m;});

    // Add empty ALT if not present in the IMG tag
    html = html.replace(/<(img)([^>]*)\/>/g,function(m,p,s){return m.indexOf('alt=') == -1 ? '<' + p + s + ' alt="" />' : m;});

    return html;
    }

    END CODE /////////////////////////////////////////////////////////////////////////

  2. #2
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Raleigh, NC
    Posts
    783
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    those are just regex replaces using callback funcitons
    use preg_replace_callback()
    http://www.php.net/manual/en/functio...e-callback.php

    the regex can probably be used verbatim

  3. #3
    SitePoint Addict molder101's Avatar
    Join Date
    Apr 2004
    Location
    dorothy
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did notice that that would be an option however the following:

    function(m,p,s)

    regex go me a little off track. I am not sure what this is referring to give there is no function like that in the script.

    Mike

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Please don't cross-post in more than one forum.

  5. #5
    SitePoint Addict molder101's Avatar
    Join Date
    Apr 2004
    Location
    dorothy
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My apologies ... I wasn't quite sure of the forum it should be located in considering its context.

    Mike

  6. #6
    SitePoint Addict molder101's Avatar
    Join Date
    Apr 2004
    Location
    dorothy
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As for the function aspect of the code it seems that could be adjusted using create_function() instead of function() ...

    I am trying to figure out how to translate preg_replace_callback into the syntax that is provided by the ASP code.

    The ASP code says:

    m.replace( * regex * ) ... etc

    PHP code:

    $m.preg_replace_callback( * regex * ) ... ??

    Doesn't seem like that is correct?

    Mike


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
  •