473,666 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Mar 16 '06 #1
1 1776
d
"rybasso" <ry*****@poczta .onet.pl> wrote in message
news:dv******** **@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="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);
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

Mar 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4317
by: TXSherry | last post by:
Hi, I cannot seem to wrap my brain around preg_replace. Though I've read the help file backwords and forwards. :/ Hoping someone can give me a solution here. Problem: Given string 'str' which may contain new lines and will contain html code, IN this string any "words" that begin with an underscore I want to replace with a given word. A word here being a group of chars preceded by a space or null (start of line) and closed by a...
1
2238
by: yawnmoth | last post by:
say i have the following script: <? $test = "aaaaa"; print '"' . preg_replace('/.*/','x',$test) . '"<br>'; $test = "\n\n\n\n\n"; print '"' . preg_replace('/.*/','x',$test) . '"'; ?> the output i would expect is as follows:
7
4994
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore and, after submitting via POST to a preg_replace filter, get back '_sometext_' (i.e., the same thing with the literal backslashes stripped)
1
2507
by: Dave | last post by:
Hi, This is an interesting problem I'm faced with. I have been trying all sorts of functions to fix it and my last resort is to ask you guys and girls. I have an array: $arr(=>"aaa",=>"bbb",=>"ccc",=>"etc"); $html='<html>....<a href="page.php?var=3">3</a><a href="page.php?var=345">345</a...<a href="page.php?var=n">n</a>...</html>';
7
2033
by: monomaniac21 | last post by:
hi all using preg_replace how can i replace the letter i in a string with nothing (delete it) when it is the last letter or it is followed by an i? i have products that are listed in a db with i or ii as in 320ii and i want to strip out the i's at the end when displaying the product name
2
1533
by: Terence | last post by:
I've been puzzling over something for ages and now give up: Does anyone see any problem with any of the following: $line = preg_replace('/\{1,6})\]/i', "<font color='# ${1}'>", $line); $line = preg_replace('/\){3}((){3})?))\]/ i', "<font color='#${1}'>", $line);
1
1296
by: K. | last post by:
Hello! I would like to use preg_replace function to leave in the result variable only: 1) letters from A to Z including Polish letters like ±¶¼³óñê including Polish upper letters like ¡¦¬£ÓÑÊ 2) letters ()-_=+!@#$%^&*`~',/\|. I have for example such varaible
3
1015
by: Silvertype | last post by:
Hi guys, I have these html tags: <input type="text" id="txtName" name="txtName" /> <textarea id="taHello" name="taHello">hello world</textarea> which I want to replace with the following tags:
5
2174
by: helraizer1 | last post by:
Hey folks and folksesses, I have written some code to get emoticons onto my image based shoutbox but there is quite a large bug, as there is with any code in the early stages, and I need your help to narrow it down for me. The idea is that the script pulls data from the database - username, colour, font and shout to print ' shout' onto the image. This part of the code all works perfectly. Then it looks through each line at a time to see if...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.