You are here: Re: preg_replace() problem « PHP Programming Language « IT news, forums, messages
Re: preg_replace() problem

Posted by d on 10/22/13 11:42

"rybasso" <rybasso@poczta.onet.pl> wrote in message
news:dvbkrc$4cb$1@srv.cyf-kr.edu.pl...
> 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="javascript" 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.arguments;
> var argc = SetCookie.arguments.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.toGMTString())) +
> ((path == null) ? "" : ("; path=" + path)) +
> ((domain == null) ? "" : ("; domain=" + domain)) +
> ((secure == true) ? "; secure" : "");
> }
>
> function getCookieVal(offset)
> {
> var endstr = document.cookie.indexOf(";",offset);
> if (endstr == -1)
> {
> endstr = document.cookie.length;
> }
> return unescape(document.cookie.substring(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.cookie.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.getElementById)
> {
> itm = document.getElementById(id);
> }
> else if (document.all)
> {
> itm = document.all[id];
> }
> else if (document.layers)
> {
> itm = document.layers[id];
> }
> if (!itm)
> {
> // do nothing
> }
> else if (itm.style)
> {
> if (itm.style.display == "none")
> {
> itm.style.display = "";
> return 1;
> }
> else
> {
> itm.style.display = "none";
> return 2;
> }
> }
> else
> {
> itm.visibility = "show";
> return 1;
> }
> }
>
> //-->
>
> </script>
> </head>
> <body>
> document body
> </body>
>
> EOF;
>
> $body = preg_replace('/<!--(.|\s)*?-->/', 'dssds', $body);

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?

> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация