how remove char around numbers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joe

    #1

    how remove char around numbers

    hello I have a string that has values in quotes 'hello' 'here' '199'
    'something else'

    I need to remove the quotes only when they are around numbers.
    To make the string lookg like 'hello' 'here' 199 'something else'
    any ideas on how to do this? thanks.

  • Aerik

    #2
    Re: how remove char around numbers

    On Apr 12, 5:47 pm, "joe" <jcha...@gmail. comwrote:
    hello I have a string that has values in quotes 'hello' 'here' '199'
    'something else'
    >
    I need to remove the quotes only when they are around numbers.
    To make the string lookg like 'hello' 'here' 199 'something else'
    any ideas on how to do this? thanks.
    Hm... use a regular expression, I'm thinking preg_replace ought to do
    the trick...

    Aerik

    Comment

    • iktorn

      #3
      Re: how remove char around numbers

      Aerik napisał(a):
      On Apr 12, 5:47 pm, "joe" <jcha...@gmail. comwrote:
      >hello I have a string that has values in quotes 'hello' 'here' '199'
      >'something else'
      >>
      >I need to remove the quotes only when they are around numbers.
      >To make the string lookg like 'hello' 'here' 199 'something else'
      >any ideas on how to do this? thanks.
      >
      Hm... use a regular expression, I'm thinking preg_replace ought to do
      the trick...
      >
      Aerik
      >
      <?php

      $txt = array("'sdfsdfs d'","'as34444'" ,"'234sdfd'","' 2344'");
      foreach ($txt as $t) {
      echo preg_replace("/^'([0-9]+)'$/","$1",$t)."\n" ;
      }

      $txt = "'sdfsdfsd' 'as34444' '12' '234sdfd' '2344'";
      echo preg_replace("/'([0-9]+)'/","$1",$txt)."\ n";

      --
      Wiktor Walc

      Comment

      • joe

        #4
        Re: how remove char around numbers

        Thanks Iktorn

        I ended up doing $where_clause_a rray = split(" ",$where_clause );
        $where_clause = "";

        foreach ($where_clause_ array as $t) {
        $where_clause = $where_clause . " " . preg_replace("/
        ^'([1-9]+)'$/","$1",$t);
        }

        I tried using echo preg_replace("/'([0-9]+)'/","$1",$txt)."\ n"; but
        It did not work. I got stuck with another preg_rplace trying to
        replace ('123123','some thingelse for (123123,'someth ingelse. If I
        could make $sql = preg_replace("/'([0-9]+)'/","$1",$sql ) work may be
        that would take care of all instances of numbers surrounde by quotes.





        On Apr 12, 11:12 pm, iktorn <s...@phpfreela ncer.netwrote:
        Aerik napisał(a):
        >
        On Apr 12, 5:47 pm, "joe" <jcha...@gmail. comwrote:
        hello I have a string that has values in quotes 'hello' 'here' '199'
        'something else'
        >
        I need to remove the quotes only when they are around numbers.
        To make the string lookg like 'hello' 'here' 199 'something else'
        any ideas on how to do this? thanks.
        >
        Hm... use a regular expression, I'm thinking preg_replace ought to do
        the trick...
        >
        Aerik
        >
        <?php
        >
        $txt = array("'sdfsdfs d'","'as34444'" ,"'234sdfd'","' 2344'");
        foreach ($txt as $t) {
        echo preg_replace("/^'([0-9]+)'$/","$1",$t)."\n" ;
        >
        }
        >
        $txt = "'sdfsdfsd' 'as34444' '12' '234sdfd' '2344'";
        echo preg_replace("/'([0-9]+)'/","$1",$txt)."\ n";
        >
        --
        Wiktor Walchttp://phpfreelancer.n et

        Comment

        Working...