PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 28th, 2012, 09:46 AM
dreamteam dreamteam is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 57 dreamteam User rank is Sergeant (500 - 2000 Reputation Level)dreamteam User rank is Sergeant (500 - 2000 Reputation Level)dreamteam User rank is Sergeant (500 - 2000 Reputation Level)dreamteam User rank is Sergeant (500 - 2000 Reputation Level)dreamteam User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 7 h 1 m 25 sec
Reputation Power: 24
Parsing through text

I haven't touched PHP in a long time and needed some help.
I have survey and in the survey once you upload the documents, it stores them as such in the database:

[{ },{ "size":"126.189"size":"126.469","name":"RFC_MarketingReqForm.docx","filename":"fu_378r8fczc3u5nen","ext":"docx"","name":"RFC_ARMCBillpay_081412.docx","filename":"fu_ws6t2urxz2qg39c","ext":"docx" },{ "size":"126.469","name":"RFC_MarketingReqForm.docx","filename":"fu_7ahdzpscp5dh82w","ext":"docx" }]

I need to go through this and pull out the filename and ext to create a url link to the documents on a custom reports page that I am creating.

PHP Code:
 $text $row['response'];
$newtext preg_split"/ (;|\"|{|}|,) /"$text ); 
$newtext explode(','$text); 
$count count($newtext); 
for (
$i 0$i $count$i++) {  
echo 
$newtext[$i] . "<br />"



I was trying to break it apart piece by piece, but I realized I am not really sure how to get the filename and ext out alone. Thank you.

Reply With Quote
  #2  
Old December 28th, 2012, 10:11 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,879 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 7 h 20 m 28 sec
Reputation Power: 813
Hi,

whoever designed this database, slap him and don't ever let him near the code again -- I hope it wasn't you?

Sh*t like this is exactly why people preach normalization, but obviously some "developers" still have never heard of it.

OK, so you have a bunch of crap data which looks like JSON. So what you'll have to do is take a JSON parser (if my guess was right) and read out the pieces you want to fetch -- in the hopes that the string isn't broken.

If you have any chance to repair the database, that's actually the first thing you should do.

Do not fumble with home-made regexes. That just makes everything even crappier.

Reply With Quote
  #3  
Old December 28th, 2012, 10:13 AM
dreamteam dreamteam is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 57 dreamteam User rank is Sergeant (500 - 2000 Reputation Level)dreamteam User rank is Sergeant (500 - 2000 Reputation Level)dreamteam User rank is Sergeant (500 - 2000 Reputation Level)dreamteam User rank is Sergeant (500 - 2000 Reputation Level)dreamteam User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 7 h 1 m 25 sec
Reputation Power: 24
It is from LimeSurvey, open source survey system.

I kept on reading and came across the same thing that it is JSON. I am trying to get it to work with json_decode, will update my progress if I succeed.

Reply With Quote
  #4  
Old December 28th, 2012, 05:54 PM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
the data you posted is corrupt. If that is a direct copy/paste from the system then you are in trouble.

I fixed the data up (I had to make up some stuff to fill in the blanks and fix the structure). I ended up with:

Code:
[{ },
{ "size":"126.469","name":"RFC_MarketingReqForm.docx","filename":"fu_378r8fczc3u5nen","ext":"docx" },
{ "size":"126.469","name":"RFC_ARMCBillpay_081412.docx","filename":"fu_ws6t2urxz2qg39c","ext":"docx" }, 
{ "size":"126.469","name":"RFC_MarketingReqForm.docx","filename":"fu_7ahdzpscp5dh82w","ext":"docx" }]


that let me call json_decode() on it, which output this array:

Code:
Array
(
    [0] => Array
        (
        )

    [1] => Array
        (
            [size] => 126.469
            [name] => RFC_MarketingReqForm.docx
            [filename] => fu_378r8fczc3u5nen
            [ext] => docx
        )

    [2] => Array
        (
            [size] => 126.469
            [name] => RFC_ARMCBillpay_081412.docx
            [filename] => fu_ws6t2urxz2qg39c
            [ext] => docx
        )

    [3] => Array
        (
            [size] => 126.469
            [name] => RFC_MarketingReqForm.docx
            [filename] => fu_7ahdzpscp5dh82w
            [ext] => docx
        )

)


so from that you could get the filename using a loop and:

PHP Code:
 $filename $array[$i]['filename'].".".$array[$i]['ext']; 


also bare in mind that json_decode($jsondata,true) will give you an assoc array which you can reference like i did above, while omitting the true will give you an object.
__________________
"Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

Looking for a project Idea?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Parsing through text

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap