SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Location
    Mumbai, India
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get some sub-string from string

    Hi. there,
    I m working on some editor. So when i make a ajax call to one API. its returne me plain text string as follows:

    while(1);
    [
    {
    "ew" : "umakant",
    "hws" : [
    "1","b","c","d","2",
    ]
    },
    ]


    I want to fetch that 1. It is one example. there may be some unicode text.
    or some alphanumeric text.
    Is there some way in PHP to get that string..?

  2. #2
    SitePoint Member
    Join Date
    Apr 2009
    Location
    Mumbai, India
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dude thanks,
    but you made a mistake...
    you thought 1 from "while(1)" but i want 1 from below row.
    "1","b","c","d","2",

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use json_decode() to turn it into a multidimensional array, but you'll need to first strip out that while statement. You could use substr() to cut the first 11 or whatever characters off, and then trim() it to take care of any remaining whitespace.

  4. #4
    SitePoint Member
    Join Date
    Apr 2009
    Location
    Mumbai, India
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks. but just one more question.
    can you tell me that suppose if i have some utf8 unicode values instead of
    that 1, b or c..
    will substring function create a problem ?

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're just using substr() to remove the junk at the start of the string before passing to json_decode(), it will be ok.


Bookmarks

Posting Permissions

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