string replace in php..?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    string replace in php..?

    hi all,
    i am newbee to php,
    for example
    Code:
    $mydata="my name is "Nirmal" Singh";
    echo $mydata;
    i want the result as
    my name is Nirmal Singh
    what should i do for this?
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Hope these help:

    [PHP]
    $mydata="my name is Nirmal Singh";
    echo $mydata;
    // my name is Nirmal Singh

    $mydata = "My name is ""Nirmal"" Singh";
    echo $mydata
    // My name is "Nirmal" Singh

    $mydata = "My name is \"Nirmal\" Singh";
    echo $mydata
    // My name is "Nirmal" Singh

    $mydata = 'My name is "Nirmal" Singh';
    echo $mydata
    // My name is "Nirmal" Singh
    [/PHP]

    Comment

    • nirmalsingh
      New Member
      • Sep 2006
      • 218

      #3
      i have already fixed data in $mydata as
      my name is "Nirmal" Singh
      now i want to regenerate $mydata as
      my name is Nirmal Singh
      what should i do?
      i hope u understand my question.

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by nirmalsingh
        i have already fixed data in $mydata as
        my name is "Nirmal" Singh
        now i want to regenerate $mydata as
        my name is Nirmal Singh
        what should i do?
        i hope u understand my question.
        I don't understand your question, because
        [PHP]
        $mydata="my name is "Nirmal" Singh";
        echo $mydata;
        [/PHP]
        will give you an error.

        Comment

        • Nert
          New Member
          • Nov 2006
          • 64

          #5
          Originally posted by nirmalsingh
          i have already fixed data in $mydata as
          my name is "Nirmal" Singh
          now i want to regenerate $mydata as
          my name is Nirmal Singh
          what should i do?
          i hope u understand my question.
          hi nirmalsingh,

          your question is a bit confusing.., if you don't mind would you please post more info about what you really want to achieve. Motoma is right, this code
          [PHP]$mydata = "my name is "Nirmal" Singh";
          echo $mydate;[/PHP] would give you an error.

          Comment

          • nirmalsingh
            New Member
            • Sep 2006
            • 218

            #6
            my problem is that, even if a string contains " symbol, i want to make it accept such as that " is not end of a string. what should i do?

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              Originally posted by nirmalsingh
              my problem is that, even if a string contains " symbol, i want to make it accept such as that " is not end of a string. what should i do?
              Take a look at the examples I posted. They gave instructions on doing just that.

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                Originally posted by nirmalsingh
                i have already fixed data in $mydata as
                my name is "Nirmal" Singh
                now i want to regenerate $mydata as
                my name is Nirmal Singh
                what should i do?
                i hope u understand my question.
                Just remove the double quotes from your string using str_replace:[php]$myname = str_replace('"' , '', $myname);[/php]
                Ronald :cool:

                Comment

                Working...