473,386 Members | 1,810 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,386 software developers and data experts.

regular expression to replace space by underscore

I am using the following code to replace spaces with "_" for my URL rewriting
function.

$url = urlencode(preg_replace("/\s/e" , "_" , $url));


It get thrown the following error and can't figure out what it's trying to tell me,

Notice: Use of undefined constant _ - assumed '_' in : regexp code on line 1

Help!

(Note: I'm using PHP Version 5.2.4)
Mar 5 '08 #1
7 13265
code green
1,726 Expert 1GB
It get thrown the following error and can't figure out what it's trying to tell me
Expand|Select|Wrap|Line Numbers
  1. Notice: Use of undefined constant _ - assumed '_' in : regexp code on line 1
When php finds characters outside quotes it knows it is useable code.
A lone word with no dollar $ in front is assumed to be a constant.
Constants should be defined before use or an error is generated
This means you have an underscore outside the quotes somewhere.
[PHP]preg_replace("/\s/e" , "_" , $url));[/PHP]
Use single quotes to avoid confusion but it may be in $url.
Mar 5 '08 #2
please i want creat a step by step online form, pls kindly give me steps to creat it thanks
Mar 5 '08 #3
Getting rid of the 'e' seemed to solve the problem.
Although I'm not sure why.

preg_replace("/\s/" , "_" , $url));
Mar 5 '08 #4
code green
1,726 Expert 1GB
The slashes indicate the beginning and end of an expression not the quotes.
So the 'e' was ouside the expression
Mar 6 '08 #5
Markus
6,050 Expert 4TB
The slashes indicate the beginning and end of an expression not the quotes.
So the 'e' was ouside the expression
As was intended; the 'e' is a modifier and, therefore, comes after the expression.
Mar 6 '08 #6
code green
1,726 Expert 1GB
And the e-modifier treats the replacement string as php code.
Mar 6 '08 #7
ronverdonk
4,258 Expert 4TB
A new thread has been split off this one. See want to lear regular expressions

Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

MODERATOR
Mar 6 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
1
by: Don | last post by:
I've created a regular expression to match everything from the word "const" to the end of the last line that doesn't end in a space-underscore characters. i.e. ...
8
by: P K | last post by:
I have an XML in which I have to comment out the <responseopt> tag the tags between this tag should not be commented I plan to use regular expressions The tags looks like this <responseopt...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
18
by: Lit | last post by:
Hi, I am looking for a Regular expression for a password for my RegExp ValidationControl Requirements are, At least 8 characters long. At least one digit At least one upper case character
0
by: altavim | last post by:
Usually when you make regular expression to extract text you are starting from simple expression. When you got to know target text, you are extending your expression. Subsequently very hard to ready...
1
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
1
by: AAaron123 | last post by:
I found this on the Internet and tried a few of them and they worked in VS2008. Actually it was in a different form but I converted to make a smaller file. The data is the same as the original. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.