Function ereg_replace() is deprecated

Posted on 2009-12-18
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
    LVL 3

    Accepted Solution


    $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

    Excellent, thanks very much!!!!!

    Author Comment

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

    Thanks again.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    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.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now