Can anyone help me understand the following scripts output?:
<?
echo preg_replace('/.*/e',"sprintf('\\ \\\')",'');
?>
The output is \ and this doesn't make a lot of sense to me.
Since \\'s in strings are interpreted as single \'s, the above sprintf
parameter is equal to \\\. The following scripts output confirms this:
<?
echo "sprintf('\\\\\ ')";
?>
Attempting to run the output of the second script (as done in the next
script), however, results in a syntax error:
<?
echo sprintf('\\\');
?>
The fact that a syntax error would result isn't particurarly surprising
since the last ' is being escaped. What is surprising, however, is
that the last script yields a syntax error whereas the first script
doesn't. Any ideas as to why? 2 3572
yawnmoth said the following on 05/11/2005 22:29: Can anyone help me understand the following scripts output?:
<? echo preg_replace('/.*/e',"sprintf('\\ \\\')",''); ?>
I would imagine you have the 2nd and 3rd arguments the wrong way round.
--
Oli
Oli Filth wrote: yawnmoth said the following on 05/11/2005 22:29: Can anyone help me understand the following scripts output?:
<? echo preg_replace('/.*/e',"sprintf('\\ \\\')",''); ?>
I would imagine you have the 2nd and 3rd arguments the wrong way round.
The order of the arguments is actually intentional. I'm trying to
replace the empty string (the third argument) with that which the
second argument would output when ran (as per the e modifier).
The following demonstrates that replacement should be taking place:
<?
echo preg_replace('/.*/','replacement' ,'');
?> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Richard B. Christ |
last post by:
I wrote the following code and it does NOT seem to work.
$search = array('/<popup*>/ie');
$replace = array('make_popup(split_tag(\\0))');
preg_replace($search, $replace, $someText);
If I try the following code, then the replacing seems to work (I just try to get a
dummy back reference \\1)
$search = array('/<p(op)up*>/ie');
|
by: Jochen Daum |
last post by:
Hi,
I'd like to use something like
preg_replace("...","$this->somefunction('\\1','\\2');", $content);
It says "Cannot find function somefunction()"
I tried some escaping, but didn't work.
|
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:
|
by: brendan |
last post by:
trying to clear out all text between the outermost
<---Message Start--->
and
<---Message End--->
tags
using snippet
|
by: Sorby |
last post by:
Hi,
My website needs to allow users to specify where a thumbnail image will
appear in the text ($articleText) they submit.
The thumbnail filenames are held in a single-dimensional array called
$photos
e.g. the users are to type to specify they want thumbnail four (
from array position 4 )
I was hoping the following expression would work, but it doesn't. The
| |
by: correo |
last post by:
Hi all!
This:
$string = preg_replace('//i', '_', $string);
replaces an accented letter with two underscores instead of one, when
the submitting page is in UTF8 ($string comes from a GET form). It
works well when the submitting page is encoded in ISO-8859-1 or with
other characters such as an ampersand or whatever. Any ideas why? TIA
|
by: rybasso |
last post by:
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:
|
by: amygdala |
last post by:
Hi there,
I'm trying to replace single quoted attributes in HTML tags with double
quotes. What I've come up with is this:
function replaceSingleQuotesInsideTags( $input )
{
$output = preg_replace(
'/<*>/e',
"str_replace( '\'', '\"', '$0' )",
|
by: Sebarry |
last post by:
Hi,
I'm a PHP newbie and I don't understand what it means about the e modifier makes preg_replace() treat the replacement parameter as PHP code after the appropriate references substitution is done.
I have a file with HTML tags such as follows.
<DIV class="bottomPostionDiv">
<H1>BENEFITS </H1></DIV>
I have a regular expression to identify the uppercase tags, which I want to convert to lowercase.
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |