473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1329
sc*********@hotmail.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*********@hotmail.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('|hello|', "hello");
preg_match('@hello@', "hello");
preg_match('/hello/', "hello");
preg_match('%hello%', "hello");
preg_match('#hello#', "hello");
preg_match('<hello>', "hello");
preg_match('?hello?', "hello");
preg_match('[hello]', "hello");
preg_match('&hello&', "hello");
preg_match('(hello)', "hello");
preg_match('=hello=', "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
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. ...
7
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
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...
12
by: pmclinn | last post by:
What is the difference between these declarations: Dim strMyData() as string and Dim strMyData as string() -Peter
2
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...
4
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...
18
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...
14
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,...
14
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. ...
16
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.