Questions tagged [ereg-replace]

ereg_replace() is a PHP function that performs string replacement using regular expressions.

ereg_replace() is a PHP function that performs string replacement using regular expressions.

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. See https://php.net/manual/en/function.ereg-replace.php.

50 questions
229
votes
3 answers

php Replacing multiple spaces with a single space

I'm trying to replace multiple spaces with a single space. When I use ereg_replace, I get an error about it being deprecated. ereg_replace("[ \t\n\r]+", " ", $string); Is there an identical replacement for it. I need to replace multiple " " white…
Dani
  • 2,293
  • 2
  • 14
  • 4
47
votes
3 answers

Replace all characters except letters, numbers, spaces and underscores

I am looking to replace all characters in a string except letters, numbers, spaces and underscores. Could someone please provide a example?
Daniel Blackmore
  • 481
  • 1
  • 5
  • 6
12
votes
2 answers

Fatal error: Uncaught Error: Call to undefined function ereg_replace() PHP 7

below code is giving me the fatal error in php 7 $jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name'])); is there any way to make it compatible with php 7?
user5247236
10
votes
4 answers

replace ereg_replace with preg_replace

Hi need to change the function ereg_replace("[\]", "", $theData) to preg_replace
user359187
  • 2,269
  • 6
  • 29
  • 44
6
votes
1 answer

Strip non alphanumeric characters from Arabic UTF8 + English string

I want to remove all non Arabic, non English and non Numbers charecters from a string, except for dashes (-). I managed to do it for non English alphanumeric characters like this: $slug = ereg_replace('[^A-Za-z0-9-]', '', $string); But for non…
Waleed Asender
  • 1,477
  • 15
  • 27
5
votes
2 answers

PHP ereg_replace deprecated

I have a script that throws me errors because I run PHP 5.3.1 What Do I have to use in the example? $row[$j] = ereg_replace("\n", "\\n", $row[$j]); Deprecated: Function ereg_replace() is deprecated in..
FFish
  • 10,964
  • 34
  • 95
  • 136
3
votes
2 answers

Need some help upgrading a tiny piece of ereg_replace

I have this line of code I use for SEO purposes. The only thing is that it has an ereg_replace function in it. Now I get "ereg_replace() is deprecated" error. Apparently it's not as simple as switching it to preg_replace and my RegEx-fu is not too…
Serhiy
  • 2,505
  • 3
  • 33
  • 49
3
votes
6 answers

How to remove initial (on the left) "+" or "0" from a telephone number string?

I need a regular expression in PHP to remove from a string of telephone numbers the + or the 0 at the beginning of a number. I have this function to remove every not-number characters ereg_replace("[^0-9]", "", $sPhoneNumber) but I need something…
axel
  • 3,778
  • 4
  • 45
  • 72
2
votes
2 answers

How replace replace all specific characters using PHP ereg_replace?

I want replace specific symbols with sign % using regular expressions on PHP. E.g. $result = ereg_replace('xlp','%','example')`. //$result = `'e%a%%me' It is possible or I should use other way?
Edgaras Karka
  • 7,400
  • 15
  • 61
  • 115
2
votes
1 answer

ereg_replace equivalent in C#

I need to know how can we use $no = ereg_replace(" .*", "", $command[$i]); equivalent in c#, I am very newbie in pattern matching, can anyone please let me know the examples of pattern matching in c#?
Aemz
  • 137
  • 1
  • 2
  • 9
2
votes
1 answer

What to change from ereg_replace to preg_replace?

I've just upgraded to php 5.4 and I've come across a common error of needing to upgrade my ereg_replace to preg_replace, but I'm a tad confused. How can I change the following ereg_replace to a…
dpDesignz
  • 1,909
  • 10
  • 34
  • 70
2
votes
3 answers

ereg_replace or preg_replace function

I will like to replace any numeric character from the 12th position of variable $key with an empty string: $key variable has 12 characters + incremented numeric characters. For example: IODN4YFK5XKV1 GYDN4YFK5XKV2 P3FU4YFK5XKV3 Bellow is my current…
1
vote
1 answer

ereg_replace to preg_replace conversion

How can i convert: ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", " ", $data); to preg_replace("......", " ", $data);
FidoBoy
  • 392
  • 6
  • 18
1
vote
2 answers

replacement for ereg_replace

Possible Duplicate: How can I convert ereg expressions to preg in PHP? I have upgraded php and now im getting the ereg_replace deprecated errors. I have done some searching round web and found that I can use preg instead but not sure how to…
1
vote
1 answer

How to replace text in regex by using "POSIX" regex

I have existing code doing in PCRE method and I would like to have same function in POSIX. Below is my example code did in PCRE.
Deno
  • 434
  • 4
  • 16
1
2 3 4