Function ereg_replace() is deprecated

Posted on 2009-12-18
Medium Priority
Last Modified: 2013-12-13

A CMS script that we use has some use of deprecated php functions since php 5.3.0 which is now throwing errors..

Function ereg_replace() is deprecated

I need a quick fix on the following ereg_replace function to make it compatible with php 5.3 so that it uses preg_replace instead.
$processedTitle = ereg_replace('[^a-zA-Z0-9\\'.$space.']', '', $processedTitle); // strip the rest
    $processedTitle = ereg_replace('\\'.$space.'+',$space,$processedTitle); // Convert multiple 'spaces' to a single one
    $processedTitle = trim($processedTitle,$space);

Open in new window

Question by:thyros
  • 2

Accepted Solution

hsq91 earned 2000 total points
ID: 26084493

$processedTitle = preg_replace('/[^a-zA-Z0-9\\'.$space.']/', '', $processedTitle); // strip the rest
    $processedTitle = preg_replace('/\\'.$space.'+/',$space,$processedTitle); // Convert multiple 'spaces' to a single one
    $processedTitle = trim($processedTitle,$space);

Author Closing Comment

ID: 31667970
Excellent, thanks very much!!!!!

Author Comment

ID: 26084661
Top man, thanks alot, your quick response saved me from a stressful night trying to troubleshoot it.

Thanks again.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question