473,785 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about array syntax

On the PHP site on the preg_replace() function page (
http://us3.php.net/manual/en/function.preg-replace.php ), example 1
uses "@" signs in the regular expression members of the "search" array.
On another PHP site (
http://www.phpfreaks.com/phpmanual/p...g-replace.html ),
Example 5 is the same script except the regex array members use double-
then single-quotes.

Why?

Both scripts seem to work the same. I can find no documentation on how
the "@" sign affects how the regex is used.

A link to explanatory documentation would be highly appreciated.

Mar 23 '06 #1
2 1345
sc*********@hot mail.com wrote:
On the PHP site on the preg_replace() function page (
http://us3.php.net/manual/en/function.preg-replace.php ), example 1
uses "@" signs in the regular expression members of the "search" array.
On another PHP site (
http://www.phpfreaks.com/phpmanual/p...g-replace.html ),
Example 5 is the same script except the regex array members use double-
then single-quotes. Why? Both scripts seem to work the same. I can find no documentation on how
the "@" sign affects how the regex is used. A link to explanatory documentation would be highly appreciated.


the "@" sign in the first example is used as the delimiter. In the second
example the delimiter is "/"

With regex - you can use almost any meta-character as a delimiter.

Mar 23 '06 #2
sc*********@hot mail.com wrote:
On the PHP site on the preg_replace() function page (
http://us3.php.net/manual/en/function.preg-replace.php ), example 1
uses "@" signs in the regular expression members of the "search" array.
On another PHP site (
http://www.phpfreaks.com/phpmanual/p...g-replace.html ),
Example 5 is the same script except the regex array members use double-
then single-quotes.

Why?

Both scripts seem to work the same. I can find no documentation on how
the "@" sign affects how the regex is used.

A link to explanatory documentation would be highly appreciated.


The @ does nothing. In accordance with PERL syntax, you can use nearly
any non-alphanumeric characters to bracket regular expressions. People
usually stick with the /expression/ format, for among other things,
that's required in Javascript. Some people like to use @expression@
because in web application, you often search for the slash character
itself.

The following all do the same thing:

preg_match('|he llo|', "hello");
preg_match('@he llo@', "hello");
preg_match('/hello/', "hello");
preg_match('%he llo%', "hello");
preg_match('#he llo#', "hello");
preg_match('<he llo>', "hello");
preg_match('?he llo?', "hello");
preg_match('[hello]', "hello");
preg_match('&he llo&', "hello");
preg_match('(he llo)', "hello");
preg_match('=he llo=', "hello");

Some are, of course, goofier than others.

Mar 23 '06 #3

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

Similar topics

3
3145
by: John Howard | last post by:
I'm working on my homework for C++, and have a problem. I have a multi-dimension array, Array1 that I can't define in the function declaration and function definition. I keep getting an error. I've tried the following: void Sum ( int ); I get an error with this, and also with: void Sum ( int );
7
11778
by: csx | last post by:
Hi everyone! two quick questions relating to arrays. Q1, Is it possible to re-assign array elements? int array = {{2,4}, {4,5}}; array = {2,3}
5
5646
by: pandapower | last post by:
Hi, I know about the equivalence of pointer and arrays.But my doubt comes when its for multidimentional arrays.I have read the C faq but still have some doubts. Suppose I have a declaration as 1. char array or char array and it will get decayed to 2. char *array
12
1275
by: pmclinn | last post by:
What is the difference between these declarations: Dim strMyData() as string and Dim strMyData as string() -Peter
2
2517
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of the array is an object itself but what is this syntax of the consecutive double quotes inside the brackets ?
4
1626
by: cjl | last post by:
As a learning exercise, I am trying to write a web-based version of 'drawbot' in PHP. See: http://just.letterror.com/ltrwiki/DrawBot I am interested in hearing ideas about how to approach the user input parsing problem. I would like to allow people to type in simple code and have it executed, but I need to limit the code they can write to a few pre-defined drawing functions, as well as control structures like loops, if thens, etc...
18
2062
by: mdh | last post by:
>From p112 ( K&R). Given an array declared as static char arr= { { 0,1,........},{0,1,.....}}; let arr be passed as an argument to f. f( int (*arr) ) {....} It is noted that the parentheses are necessary else it would be
14
1777
by: ablock | last post by:
I have an array to which i have a added a method called contains. I would like to transverse this array using for...in...I understand fully that for...in is really meant for Objects and not Arrays, but I purposely had this array filled unsequentially because the key for the array is meant to act as an ID which has a contextual meaning in my script. The problem, of course, is that for...in also returns my method 'contains' as one of the...
14
4270
by: rohitkumar | last post by:
this is my code to calculate the sum of digits in a number for eg. 432567 sum =4+3+2+5+6+7=27 i 'm using turboc++ compiler from borland and i 'm runing my program on DOS. #include<iostream.h> #include<conio.h> long poweroften(int); //to calculate power of 10
16
309
by: mdh | last post by:
I have a question about the library function strcpy. In K&R on page 109, strcpy is used to copy a line ( line ) to a pointer (char *), which is first allocated space by K&Rs "alloc" function. In a few pages prior to this, the example that K&R showed used this definition for it's version of strcpy void strcpy( char *s, char *t){ while ( *s++ = *t++);
0
9645
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
9480
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
10327
Oralloy
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...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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...
0
8973
agi2029
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...
1
7499
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
6740
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();...
1
4053
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 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.