Jump to content

Recommended Posts

I am looking for a way to parse a file that contains a lot of text that is comma separated, yet it is not a csv. 

What i want is to find a keyword then echo that keyword and a few characters after that keyword, then look for another keyword and echo that keyword and some characters after that keyword...etc.

 

Can someone point me in the right direction please?

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/277319-help-parse-text-file-find-keyword/
Share on other sites

Ok here is what I have and what I need it to look like:

 

Sample file:

 

{"RubricCriterion":[{"num":1,"value":"25","previous_version":null,"position":1,"name":"Writing","description":null,"rubric":352600,"criterion_scales":[10985652,10985648,10985644,10985640],"id":3423222},{"num":2,"value":"25","previous_version":null,"position":2,"name":"Grammar","description":null,"rubric":352600,"criterion_scales":[10985651,10985647,10985643,10985639],"id":3423223},{"num":3,"value":"25","previous_version":null,"position":3,"name":"Punctuation","description":null,"rubric":352600,"criterion_scales":[10985650,10985646,10985642,10985638],"id":3423224},{"num":4,"value":"25","previous_version":null,"position":4,"name":"Spelling","description":null,"rubric":352600,"criterion_scales":[10985649,10985645,10985641,10985637],"id":3423225}],"Rubric":[{"cv_loaded":"1","criterion":[3423222,3423223,3423224,3423225],"assignments":[],"id":352600,"papers_scored":"0","owner":1006900964,"criterion_scales_all":[10985652,10985648,10985644,10985640,10985651,10985647,10985643,10985639,10985650,10985646,10985642,10985638,10985649,10985645,10985641,10985637],"name":"MyRubric","deleted":0,"description":null,"distribute_criterion_percentage":0,"total_points":null,"scoring_method":2,"scale_values":[3343228,3343229,3343230,3343231],"rubric_group":null}],"RubricScale":[{"num":1,"value":"25","position":1,"name":"Not Acceptable","id":3343228,"rubric":352600},{"num":2,"value":"50","position":2,"name":"Beginner","id":3343229,"rubric":352600},{"num":3,"value":"75","position":3,"name":"Competent","id":3343230,"rubric":352600},{"num":4,"value":"100","position":4,"name":"Proficient","id":3343231,"rubric":352600}],"RubricCriterionScale":[{"scale_value":3343228,"value":"0","criterion":3423222,"id":10985652,"description":"poor writing"},{"scale_value":3343229,"value":"0","criterion":3423222,"id":10985648,"description":"begineer writing"},{"scale_value":3343230,"value":"0","criterion":3423222,"id":10985644,"description":"competent writing"},{"scale_value":3343231,"value":"0","criterion":3423222,"id":10985640,"description":"proficient writing"},{"scale_value":3343228,"value":"0","criterion":3423223,"id":10985651,"description":"poor grammar"},{"scale_value":3343229,"value":"0","criterion":3423223,"id":10985647,"description":"beginner grammar"},{"scale_value":3343230,"value":"0","criterion":3423223,"id":10985643,"description":"competent grammar"},{"scale_value":3343231,"value":"0","criterion":3423223,"id":10985639,"description":"proficient grammar"},{"scale_value":3343228,"value":"0","criterion":3423224,"id":10985650,"description":null},{"scale_value":3343229,"value":"0","criterion":3423224,"id":10985646,"description":null},{"scale_value":3343230,"value":"0","criterion":3423224,"id":10985642,"description":null},{"scale_value":3343231,"value":"0","criterion":3423224,"id":10985638,"description":null},{"scale_value":3343228,"value":"0","criterion":3423225,"id":10985649,"description":null},{"scale_value":3343229,"value":"0","criterion":3423225,"id":10985645,"description":null},{"scale_value":3343230,"value":"0","criterion":3423225,"id":10985641,"description":null},{"scale_value":3343231,"value":"0","criterion":3423225,"id":10985637,"description":null}]}

 

 

 

Desired Output (i will format the html to make it pretty)

ZfP1ylH.jpg

why does it work when I insert it into $string and it doesn't when I don't

 

<?
$file = "rbc/$_GET[parse]";
$string = json_decode(file_get_contents($file, true));

foreach ($string->RubricCriterion as $rubric) {
    echo $rubric->name;
}
?>
EDIT [ignace]: I accidently edited your post mistaken it for quoting you so the wording may be different, my apologies Edited by ignace

you mean like this?

 

<?php
$file  = "rbc/" . basepath($_GET['parse']);

if (!file_exists($file)) {
  printf("file %s does not exist", $file);
  exit;
}

foreach (json_decode(file_get_contents($file, true))->RubricCriterion as $rubric) {
    echo $rubric->name;
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.