/    Sign up×
Community /Pin to ProfileBookmark

REGEX: Search / Replace text in Variable

I have some data that is being pulled from a database that I want formated and I am wondering if REGEX would be the best thing to use to add said formatting:

[list]

  • [*]

    Format first instance of “General:” to “<strong>General:</strong>”


  • [*]

    Format first instance of “Points of Interest Ashore:” to “<br /><strong>Points of Interest Ashore:</strong>”


  • [*]

    Format first instance of “Points of Interest Afloat:” to “<br /><strong>Points of Interest Afloat:</strong>”


  • [/list]

    [code=php]
    # Variable containing TEXT data from database
    /* Example of text contained in string object $data:

    “General: Includes the chart from just north of the Bay Bridge to Herring Bay. Points of Interest Ashore: Annapolis, U.S. Naval Academy, Sandy Point State Park, and Deale. Points of Interest Afloat: Severn River to upstream of the Rte 50 bridge, Whitehall Bay, South River the entire West, and Rhode Rivers, and Herring Bay.
    */

    $data = $rs->[“description”];

    [/code]

    to post a comment
    PHP

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @CompGeek01Jul 25.2005 — Yes, using a regular expression for this type of work is what they are made for. Use preg_replace()

    http://us2.php.net/preg_replace
    Copy linkTweet thisAlerts:
    @kouki0196authorJul 26.2005 — Yes, using a regular expression for this type of work is what they are made for. Use preg_replace()

    http://us2.php.net/preg_replace[/QUOTE]


    Perfect! I found an example in there that fit my problem perfectly. ?
    ×

    Success!

    Help @kouki0196 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...