preg_replace() problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rybasso

    #1

    preg_replace() problem

    Hello,

    Does anyone has an idea why preg_replace() cause 'This page contains no
    data' in FF and 'This page could not be found' in IE.

    I spend a lot of time searching any ideas on newsgroups but found
    nothing corresponding.

    Here is the code:

    $body = <<<EOF

    <script language="javas cript" type="text/javascript">

    <!--
    var expDays = 90;
    var exp = new Date();
    var tmp = '';
    var tmp_counter = 0;
    var tmp_open = 0;

    exp.setTime(exp .getTime() + (expDays*24*60* 60*1000));

    function SetCookie(name, value)
    {
    var argv = SetCookie.argum ents;
    var argc = SetCookie.argum ents.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTSt ring())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }

    function getCookieVal(of fset)
    {
    var endstr = document.cookie .indexOf(";",of fset);
    if (endstr == -1)
    {
    endstr = document.cookie .length;
    }
    return unescape(docume nt.cookie.subst ring(offset, endstr));
    }

    function GetCookie(name)
    {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie .length;
    var i = 0;
    while (i < clen)
    {
    var j = i + alen;
    if (document.cooki e.substring(i, j) == arg)
    return getCookieVal(j) ;
    i = document.cookie .indexOf(" ", i) + 1;
    if (i == 0)
    break;
    }
    return null;
    }

    function ShowHide(id1, id2, id3)
    {
    var res = expMenu(id1);
    if (id2 != '') expMenu(id2);
    if (id3 != '') SetCookie(id3, res, exp);
    }

    function expMenu(id)
    {
    var itm = null;
    if (document.getEl ementById)
    {
    itm = document.getEle mentById(id);
    }
    else if (document.all)
    {
    itm = document.all[id];
    }
    else if (document.layer s)
    {
    itm = document.layers[id];
    }
    if (!itm)
    {
    // do nothing
    }
    else if (itm.style)
    {
    if (itm.style.disp lay == "none")
    {
    itm.style.displ ay = "";
    return 1;
    }
    else
    {
    itm.style.displ ay = "none";
    return 2;
    }
    }
    else
    {
    itm.visibility = "show";
    return 1;
    }
    }

    //-->

    </script>
    </head>
    <body>
    document body
    </body>

    EOF;

    $body = preg_replace('/<!--(.|\s)*?-->/', 'dssds', $body);
    echo $body;

    but with:
    $body = preg_replace('/(\s)/', ' ', $body);
    $body = preg_replace('/<!--.*-->/', 'dssds', $body);

    Works OK...

    For me its strange, any ideas where I did a mistake?

    Regards,
    Rybasso
  • d

    #2
    Re: preg_replace() problem

    "rybasso" <rybasso@poczta .onet.pl> wrote in message
    news:dvbkrc$4cb $1@srv.cyf-kr.edu.pl...[color=blue]
    > Hello,
    >
    > Does anyone has an idea why preg_replace() cause 'This page contains no
    > data' in FF and 'This page could not be found' in IE.
    >
    > I spend a lot of time searching any ideas on newsgroups but found nothing
    > corresponding.
    >
    > Here is the code:
    >
    > $body = <<<EOF
    >
    > <script language="javas cript" type="text/javascript">
    >
    > <!--
    > var expDays = 90;
    > var exp = new Date();
    > var tmp = '';
    > var tmp_counter = 0;
    > var tmp_open = 0;
    >
    > exp.setTime(exp .getTime() + (expDays*24*60* 60*1000));
    >
    > function SetCookie(name, value)
    > {
    > var argv = SetCookie.argum ents;
    > var argc = SetCookie.argum ents.length;
    > var expires = (argc > 2) ? argv[2] : null;
    > var path = (argc > 3) ? argv[3] : null;
    > var domain = (argc > 4) ? argv[4] : null;
    > var secure = (argc > 5) ? argv[5] : false;
    > document.cookie = name + "=" + escape(value) +
    > ((expires == null) ? "" : ("; expires=" + expires.toGMTSt ring())) +
    > ((path == null) ? "" : ("; path=" + path)) +
    > ((domain == null) ? "" : ("; domain=" + domain)) +
    > ((secure == true) ? "; secure" : "");
    > }
    >
    > function getCookieVal(of fset)
    > {
    > var endstr = document.cookie .indexOf(";",of fset);
    > if (endstr == -1)
    > {
    > endstr = document.cookie .length;
    > }
    > return unescape(docume nt.cookie.subst ring(offset, endstr));
    > }
    >
    > function GetCookie(name)
    > {
    > var arg = name + "=";
    > var alen = arg.length;
    > var clen = document.cookie .length;
    > var i = 0;
    > while (i < clen)
    > {
    > var j = i + alen;
    > if (document.cooki e.substring(i, j) == arg)
    > return getCookieVal(j) ;
    > i = document.cookie .indexOf(" ", i) + 1;
    > if (i == 0)
    > break;
    > }
    > return null;
    > }
    >
    > function ShowHide(id1, id2, id3)
    > {
    > var res = expMenu(id1);
    > if (id2 != '') expMenu(id2);
    > if (id3 != '') SetCookie(id3, res, exp);
    > }
    >
    > function expMenu(id)
    > {
    > var itm = null;
    > if (document.getEl ementById)
    > {
    > itm = document.getEle mentById(id);
    > }
    > else if (document.all)
    > {
    > itm = document.all[id];
    > }
    > else if (document.layer s)
    > {
    > itm = document.layers[id];
    > }
    > if (!itm)
    > {
    > // do nothing
    > }
    > else if (itm.style)
    > {
    > if (itm.style.disp lay == "none")
    > {
    > itm.style.displ ay = "";
    > return 1;
    > }
    > else
    > {
    > itm.style.displ ay = "none";
    > return 2;
    > }
    > }
    > else
    > {
    > itm.visibility = "show";
    > return 1;
    > }
    > }
    >
    > //-->
    >
    > </script>
    > </head>
    > <body>
    > document body
    > </body>
    >
    > EOF;
    >
    > $body = preg_replace('/<!--(.|\s)*?-->/', 'dssds', $body);[/color]

    If you add the s pattern modifier (after your last slash), you can write it
    without the |\s as the dot will take care of it.

    Have you tried actually looking at what is sent to the browser?
    [color=blue]
    > echo $body;
    >
    > but with:
    > $body = preg_replace('/(\s)/', ' ', $body);
    > $body = preg_replace('/<!--.*-->/', 'dssds', $body);
    >
    > Works OK...
    >
    > For me its strange, any ideas where I did a mistake?
    >
    > Regards,
    > Rybasso[/color]


    Comment

    Working...