Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: string problem

  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    string problem

    Hello

    I have a big $text_log variable containing this

    value1 value2 value3 -value4-
    value1 value2 value3 -value4-
    value1 value2 value3 -value4-
    ....
    ....
    value1 value2 value3 -value4-
    value1 value2 value3 -value4-


    I need to replace the 1th "-" of each line with nothing ""
    and the last "-" of each line with a space " ".
    Only in this way I could explode $text correctly for my array
    usage .

    How to do ?

    I tried with str_replace , without success .

    Any idea how can do that ?

    Thank you

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    you could quickly do this regular expressions.

    something like:

    PHP Code:
    $text_log preg_replace('/(-)(\w+)(-)/','$2 ',$text_log); 
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    PHP Code:
    $text_log preg_replace("/(-)(.+?)(-)/","\\2 ",$text_log); 
    PHP 5 & MySQL 5 (Y)

  • #4
    New Coder
    Join Date
    Nov 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •