I've been noticing some odd behavior while experimenting with benchmarking SplFixedArrays. Take this little snippet of code, for instance...
<?php
$splFixedArray = new \SplFixedArray( 100000 );
echo number_format( memory_get_usage() ) . PHP_EOL;
$variable = 'Truffaut single-origin coffee wayfarers, church-key asymmetrical 90\'s trust fund hashtag before they sold out thundercats photo booth. Godard sustainable roof party keffiyeh, Odd Future chillwave mlkshk kogi VHS leggings hoodie art party next level dreamcatcher yr. Blog american apparel aesthetic tattooed farm-to-table, stumptown viral whatever mixtape raw denim Williamsburg skateboard flexitarian actually tofu. Echo Park lomo disrupt PBR, jean shorts irony fingerstache blog kale chips. Street art iPhone PBR fingerstache Bushwick Cosby sweater. McSweeney\'s mumblecore semiotics, twee quinoa tofu +1 fingerstache pop-up. Echo Park bitters disrupt irony. Truffaut single-origin coffee wayfarers, church-key asymmetrical 90\'s trust fund hashtag before they sold out thundercats photo booth. Godard sustainable roof party keffiyeh, Odd Future chillwave mlkshk kogi VHS leggings hoodie art party next level dreamcatcher yr. Blog american apparel aesthetic tattooed farm-to-table, stumptown viral whatever mixtape raw denim Williamsburg skateboard flexitarian actually tofu. Echo Park lomo disrupt PBR, jean shorts irony fingerstache blog kale chips. Street art iPhone PBR fingerstache Bushwick Cosby sweater.';
var_dump( $variable );
for( $i = 0; $i < 100000; $i++ )
{
$splFixedArray[ $i ] = $variable;
}
echo number_format( memory_get_usage() );
Which outputs...
1,032,080
string(1209) "Truffaut single-origin coffee wayfarers, church-key asymmetrical 90's trust fund hashtag before they sold out thundercats photo booth. Godard sustainable roof party keffiyeh, Odd Future chillwave mlkshk kogi VHS leggings hoodie art party next level dreamcatcher yr. Blog american apparel aesthetic tattooed farm-to-table, stumptown viral whatever mixtape raw denim Williamsburg skateboard flexitarian actually tofu. Echo Park lomo disrupt PBR, jean shorts irony fingerstache blog kale chips. Street art iPhone PB"...
1,032,384
Now, let's add a simple random integer onto the end while in the for loop...
<?php
$splFixedArray = new \SplFixedArray( 100000 );
echo number_format( memory_get_usage() ) . PHP_EOL;
$variable = 'Truffaut single-origin coffee wayfarers, church-key asymmetrical 90\'s trust fund hashtag before they sold out thundercats photo booth. Godard sustainable roof party keffiyeh, Odd Future chillwave mlkshk kogi VHS leggings hoodie art party next level dreamcatcher yr. Blog american apparel aesthetic tattooed farm-to-table, stumptown viral whatever mixtape raw denim Williamsburg skateboard flexitarian actually tofu. Echo Park lomo disrupt PBR, jean shorts irony fingerstache blog kale chips. Street art iPhone PBR fingerstache Bushwick Cosby sweater. McSweeney\'s mumblecore semiotics, twee quinoa tofu +1 fingerstache pop-up. Echo Park bitters disrupt irony. Truffaut single-origin coffee wayfarers, church-key asymmetrical 90\'s trust fund hashtag before they sold out thundercats photo booth. Godard sustainable roof party keffiyeh, Odd Future chillwave mlkshk kogi VHS leggings hoodie art party next level dreamcatcher yr. Blog american apparel aesthetic tattooed farm-to-table, stumptown viral whatever mixtape raw denim Williamsburg skateboard flexitarian actually tofu. Echo Park lomo disrupt PBR, jean shorts irony fingerstache blog kale chips. Street art iPhone PBR fingerstache Bushwick Cosby sweater.';
var_dump( $variable );
for( $i = 0; $i < 100000; $i++ )
{
$splFixedArray[ $i ] = $variable . rand();
}
echo number_format( memory_get_usage() );
Which results in this...
1,034,320
string(1209) "Truffaut single-origin coffee wayfarers, church-key asymmetrical 90's trust fund hashtag before they sold out thundercats photo booth. Godard sustainable roof party keffiyeh, Odd Future chillwave mlkshk kogi VHS leggings hoodie art party next level dreamcatcher yr. Blog american apparel aesthetic tattooed farm-to-table, stumptown viral whatever mixtape raw denim Williamsburg skateboard flexitarian actually tofu. Echo Park lomo disrupt PBR, jean shorts irony fingerstache blog kale chips. Street art iPhone PB"...
129,834,272
What I'm curious about is why function calls are resulting in stacked memory usage. Is it normal that memory would not be freed up after the iteration?
This behavior is expected.
In the first case, you are storing the same value multiple times, which can be implemented as a single instance of the value and a batch of references to it, with a copy-on-write semantic for cases when the value at a given array index is changed.
In the second case, you are storing many different values, which can't be handled the same way; memory must be allocated for the full contents of each value, which results in the difference you see in memory consumption between the two cases.
Related
My English is poor. I'm sorry if there is anything rude.
Thank you for taking the time to read my question.
When I use PHP function json_decode(), i get null and json_last_error() throws 4.
Thanks for helping!
my PHP code is
$str = file_get_contents("cache.txt");
$str = htmlspecialchars_decode($str);
$arr = json_decode($str, true);
print_r($arr);
echo $errorinfo = json_last_error();
the content of File named cache.txt is:
[[1,[0,"wWfxgeyEgrRf1M",["https://encrypted-tbn0.gstatic.com/images?q\u003dtbn%3AANd9GcTFekou1VcAkVW23s69_Q53CsUJD0syjACwY0jHbRYcRIcr5cyp",225,225],["https://www.hijordan.com/image/cache/catalog/Jordan-Retro-1/Jordan-Retro-1-16-1080x1080.jpg",1080,1080],null,2,"rgb(160,42,51)",null,false,{"2001":[null,null,null,21,18,3,3,null,null,null,[]],"2003":[null,"M3A7LEiRdcA0DM","https://www.aljadid.com/efabshop/air-jordan-retro-1-red-black-white-p-16.html","Nike Air Jordan Retro 1 Red Black White - Buy Air Jordan 1 Retro ...",null,false,null,null,null,false,null,null,"Al Jadid",null,null,null,null,null,null,null,null,null,false,false,false,{"26":[null,2]}],"2006":[null,[4.0,null,"Air Jordan Retro 1 red black white",null,"A stepping stone to the world of Air Jordan is the Original air jordan 1 (I) White Black Red, which was worn by Michael Jordan the majority of the ...",null,true,5,60.85,"USD"]],"2008":[null,"Nike Air Jordan Retro 1 Red Black White ..."],"183836587":["aljadid.com"]}],null,[177,158,null,null,null,177,177,null,null,-10,null,null,false,true,null,null,[]],0,null,null,"wWfxgeyEgrRf1M",1,null,null,null,null,[[1580879352798185,178652430,3708684377],null,2]],[1,[0,"sFUMQKdZQFRaGM",["https://encrypted-tbn0.gstatic.com/images?q\u003dtbn%3AANd9GcSV5L3VvYWthX-IG9QO5QfLN_6eLvA687_og435LmF6_5NmGSI4",225,225],["https://www.hijordan.com/image/cache/catalog/air-jordan-12/air-jordan-12-49-1080x1080.jpg",1080,1080],null,2,"rgb(160,58,51)",null,false,{"2001":[null,null,null,21,18,3,6,null,null,null,[]],"2003":[null,"pTPqQEjGfZF7JM","https://togaf9-cert.opengroup.org/bcabshop/air-jordan-12-retro-black-varsity-red-p-1138.html","Air Jordan 12 Retro Black Varsity Red , Price: $89.90 - Air Jordan ...",null,false,null,null,null,false,null,null,"TOGAF? 9 Certification",null,null,null,null,null,null,null,null,null,false,false,false,{"26":[null,2]}],"2006":[null,[4.0,null,"Air Jordan 12 Retro Black Varsity Red","Nike","You should not miss the chance if you have not got one like the Air Jordan 12 Retro Black Varsity Red. Fine craftsmanship with premium materials like ...",null,true,5,89.9,"USD"]],"2008":[null,"Air Jordan 12 Retro Black Varsity Red ..."],"183836587":["togaf9-cert.opengroup.org"]}],],]
I can separate data from the plain text below with Regex.
Plain text:
190.A 42-year-old male patient has been delivered to a hospital in a grave condition with dyspnea, cough with expectoration of purulent
sputum, fever up to 39,5 oC.The ?rst symptoms appeared 3 weeks ago.
Two weeks ago, a local therapist diagnosed him wi- th acute
right-sided pneumonia. Over the last 3 days, the patient’s condition
deteriorated: there was a progress of dyspnea, weakness, lack of
appetite. Chest radiography con?rms a rounded shadow in the lower lobe
of the right lung with a horizontal?uid level, the right si- nus is
not clearly visualized. What is the most likely diagnosis? A.Abscess
of the right lung B.Acute pleuropneumonia C.Right pulmonary empyema
D.Atelectasis of the right lung E.Pleural effusion 191.An 11-year-old
boy complains of general weakness, fever up to 38,2 oC, pain and
swelli- ng of the knee joints, feeling of irregular heartbeat. 3 weeks
ago, the child had quinsy. Knee joints are swollen, the overlying skin
and skin of the knee region is reddened, local temperature is
increased, movements are li- mited. Heart sounds are muf?ed,
extrasystole is present, auscultation reveals apical systolic murmur
that is not conducted to the left ingui- nal region. ESR is 38 mm/h.
CRP is 2+, anti- streptolysin O titre - 40 0. What is the most likely
diagnosis? A.Acute rheumatic fever B.Vegetative dysfunction
C.Non-rheumatic carditis D.Juvenile rheumatoid arthritis E.Reactive
arthritis 192.A 28-year-old male patient complains of sour
regurgitation, cough and heartburn that occurs every day after having
meals, when bending forward or lying down. These problems have been
observed for 4 years. Objective status and laboratory values are
normal. FEGDS revealed endoesophagitis. What is the leading factor in
the development of this disease? A.Failure of the lower esophageal
sphincter B.Hypersecretion of hydrochloric acid C.Duodeno-gastric
re?ux D.Hypergastrinemia E.Helicobacter pylori infection 193.On
admission a 35-year-old female reports acute abdominal pain, fever up
to 38,8 oC, mucopurulent discharges. The pati- ent is nulliparous, has
a history of 2 arti?cial abortions. The patient is unmarried, has
sexual Krok 2 Medicine 20 14 24 contacts. Gynecological examination
reveals no uterus changes. Appendages are enlarged, bilaterally
painful. There is profuse purulent vaginal discharge. What study is
required to con?rm the diagnosis? A.Bacteriologic and bacteriascopic
studies B.Hysteroscopy C.Curettage of uterine cavity D.Vaginoscopy
E.Laparoscopy
What did I do for this?
For the question section:
/(\d+)\.\s*([A-Z].*?)\s+([A-Z]\..*?)(?=\d+\.\s*[A-Z]|$)/s
For the options of question section:
/\s+(?=[A-Z0-9][,.:])
PHP:
$soruAlimPattern = [
'q&a' => '/(\d+)\.\s*([A-Z].*?)\s+([A-Z]\..*?)(?=\d+\.\s*[A-Z]|$)/s',
'answers' => '/\s+(?=[A-Z0-9][,.:])/'
];
$res = [];
if (preg_match_all($soruAlimPattern['q&a'], $temizSoruCikisi, $out, PREG_SET_ORDER) > 0) {
foreach ($out AS $k => $v) {
// remove the full match ($0)
$res[$k] = array_slice($v, 1, 3);
// split the answers
$res[$k][2] = preg_split($soruAlimPattern['answers'], $res[$k][2]);
}
}
$sorularJsonKodlaniyor = json_encode($res);
[...]
I can distinguish between question and question options, but is it possible to use a single Regex code instead of 2 different Regex?
I don't know how quality the PHP code is but it works.
My problem:
1. Sometimes there are unidentifiable letters in the question and these
undefined characters are indicated with a question mark. For
example: `fever up to 39,5 oC.The ?rst symptoms` or `..39,5 oC.The ?rst symptoms..`
2. Due to the numerical values in the question, the Regex code divides the question in half. For example: `... anti- streptolysin O titre - 40 0. What is the most likely diagnosis? ` In fact, the question divides the question because of the number "zero".
Expected JSON Format:
[
{
"question": "190.A 42-year-old male patient has been delivered to a hospital in a grave condition with dyspnea, cough with expectoration of purulent sputum, fever up to 39,5 oC.The ?rst symptoms appeared 3 weeks ago. Two weeks ago, a local therapist diagnosed him wi- th acute right-sided pneumonia. Over the last 3 days, the patient’s condition deteriorated: there was a progress of dyspnea, weakness, lack of appetite. Chest radiography con?rms a rounded shadow in the lower lobe of the right lung with a horizontal?uid level, the right si- nus is not clearly visualized. What is the most likely diagnosis? ",
"answers": [
"A.Abscess of the right lung ",
"B.Acute pleuropneumonia ",
"C.Right pulmonary empyema ",
"D.Atelectasis of the right lung ",
"E.Pleural effusion 1"
]
},
{
"question": "191.An 11-year-old boy complains of general weakness, fever up to 38,2 oC, pain and swelli- ng of the knee joints, feeling of irregular heartbeat. 3 weeks ago, the child had quinsy. Knee joints are swollen, the overlying skin and skin of the knee region is reddened, local temperature is increased, movements are li- mited. Heart sounds are muf?ed, extrasystole is present, auscultation reveals apical systolic murmur that is not conducted to the left ingui- nal region. ESR is 38 mm/h. CRP is 2+, anti- streptolysin O titre - 40 0. What is the most likely diagnosis? ",
"answers": [
"A.Acute rheumatic fever ",
"B.Vegetative dysfunction ",
"C.Non-rheumatic carditis ",
"D.Juvenile rheumatoid arthritis ",
"E.Reactive arthritis 1"
]
},
{
"question": "192.A 28-year-old male patient complains of sour regurgitation, cough and heartburn that occurs every day after having meals, when bending forward or lying down. These problems have been observed for 4 years. Objective status and laboratory values are normal. FEGDS revealed endoesophagitis. What is the leading factor in the development of this disease? ",
"answers": [
"A.Failure of the lower esophageal sphincter ",
"B.Hypersecretion of hydrochloric acid ",
"C.Duodeno-gastric re?ux ",
"D.Hypergastrinemia ",
"E.Helicobacter pylori infection 1"
]
},
{
"question": "193.On admission a 35-year-old female reports acute abdominal pain, fever up to 38,8 oC, mucopurulent discharges. The pati- ent is nulliparous, has a history of 2 arti?cial abortions. The patient is unmarried, has sexual Krok 2 Medicine 20 14 24 contacts. Gynecological examination reveals no uterus changes. Appendages are enlarged, bilaterally painful. There is profuse purulent vaginal discharge. What study is required to con?rm the diagnosis? ",
"answers": [
"A.Bacteriologic and bacteriascopic studies ",
"B.Hysteroscopy ",
"C.Curettage of uterine cavity ",
"D.Vaginoscopy ",
"E.Laparoscopy 1"
]
}
]
How can I overcome these problems?
What you might do is use preg_split to get all the strings with the right characters at the start like 190.A or A.
\b(?=(?:\d+|[A-Z])\.[A-Z])
\b Word boundary
(?= Positive lookahead, assert what is on the right is
(?:\d+|[A-Z]) Match either 1+ digits or a single char A-Z
\.[A-Z] Match . and a single char A-Z
) Close positive lookahead
Regex demo | Php demo
If you have all those entries in an array, you could for example use array_reduce to the get array structure that you need for the json output.
$pattern = "/\b(?=(?:\d+|[A-Z])\.[A-Z])/";
$result = preg_split($pattern, $data, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$result = array_reduce($result, function($carry, $item){
// If the string starts with a digit
if (ctype_digit(substr($item, 0, 1))) {
// Create the questions key
$carry[] = ["question" => $item];
return $carry;
}
// Get reference to the last added array in $carry
end($carry);
$last = &$carry[key($carry)];
// Create the answers key
array_key_exists("answers", $last) ? $last["answers"][] = $item : $last["answers"] = [$item];
return $carry;
}, []);
print_r(json_encode($result))
Output
[
{
"question": "190.A 42-year-old male patient has been delivered to a hospital in a grave condition with dyspnea, cough with expectoration of purulent sputum, fever up to 39,5 oC.The ?rst symptoms appeared 3 weeks ago. Two weeks ago, a local therapist diagnosed him wi- th acute right-sided pneumonia. Over the last 3 days, the patient\u2019s condition deteriorated: there was a progress of dyspnea, weakness, lack of appetite. Chest radiography con?rms a rounded shadow in the lower lobe of the right lung with a horizontal?uid level, the right si- nus is not clearly visualized. What is the most likely diagnosis? ",
"answers": [
"A.Abscess of the right lung ",
"B.Acute pleuropneumonia ",
"C.Right pulmonary empyema ",
"D.Atelectasis of the right lung ",
"E.Pleural effusion "
]
},
{
"question": "191.An 11-year-old boy complains of general weakness, fever up to 38,2 oC, pain and swelli- ng of the knee joints, feeling of irregular heartbeat. 3 weeks ago, the child had quinsy. Knee joints are swollen, the overlying skin and skin of the knee region is reddened, local temperature is increased, movements are li- mited. Heart sounds are muf?ed, extrasystole is present, auscultation reveals apical systolic murmur that is not conducted to the left ingui- nal region. ESR is 38 mm\/h. CRP is 2+, anti- streptolysin O titre - 40 0. What is the most likely diagnosis? ",
"answers": [
"A.Acute rheumatic fever ",
"B.Vegetative dysfunction ",
"C.Non-rheumatic carditis ",
"D.Juvenile rheumatoid arthritis ",
"E.Reactive arthritis "
]
},
{
"question": "192.A 28-year-old male patient complains of sour regurgitation, cough and heartburn that occurs every day after having meals, when bending forward or lying down. These problems have been observed for 4 years. Objective status and laboratory values are normal. FEGDS revealed endoesophagitis. What is the leading factor in the development of this disease? ",
"answers": [
"A.Failure of the lower esophageal sphincter ",
"B.Hypersecretion of hydrochloric acid ",
"C.Duodeno-gastric re?ux ",
"D.Hypergastrinemia ",
"E.Helicobacter pylori infection "
]
},
{
"question": "193.On admission a 35-year-old female reports acute abdominal pain, fever up to 38,8 oC, mucopurulent discharges. The pati- ent is nulliparous, has a history of 2 arti?cial abortions. The patient is unmarried, has sexual Krok 2 Medicine 20 14 24 contacts. Gynecological examination reveals no uterus changes. Appendages are enlarged, bilaterally painful. There is profuse purulent vaginal discharge. What study is required to con?rm the diagnosis? ",
"answers": [
"A.Bacteriologic and bacteriascopic studies ",
"B.Hysteroscopy ",
"C.Curettage of uterine cavity ",
"D.Vaginoscopy ",
"E.Laparoscopy"
]
}
]
i have json string but when i am getting it json_decode() it is showing blank.
$str = '[{"actcode":"Auck4","actname":"Sky Tower","date":"","time":"","timeduration":"","adult":"0","adultprice":"28","child":"0","childprice":"0","description":"Discover the best of Auckland in half a day. Soak up spectacular sights on this scenic tour, from heritage-listed buildings on Queen Street to the stunning Viaduct Harbour and panoramic vistas from the Sky Tower observation deck.
Start your tour with a hotel pick-up and travel through Auckland?s dynamic Central Business District. Travel across the iconic Auckland Harbour Bridge and admire stunning city views. Then, return to the city centre and visit the vibrant precinct of Wynyard Quarter. Here, wander among the sculptures and enjoy the happenings on the water of Viaduct Harbour.
Continue to Queen Street, also known as the ?Golden Mile? of Aucklands business and shopping district. Marvel at historic buildings like the Ferry Terminal building before visiting the Auckland Museum. Here, explore fascinating exhibits paying tribute to New Zealands natural, Maori and European histories. Afterwards, travel along Aucklands most expensive residential streets with fantastic views of the Waitemata Harbour and its islands.
Your tour ends at Sky Tower, the tallest free-standing structure in the Southern Hemisphere. Take in breathtaking 360-degree views of the city and its surroundings. In the afternoon, continue your own exploration of Auckland."}]';
i tried the below code
$array = json_decode($str,true);
echo print_r($array);
this one too
$str1 = trim($str);
$array = json_decode($str1,true);
echo print_r($array);
but the string si showing blank
try this one.
$string = mysql_real_escape_string($str);
$findsym = array('\r', '\n');
$removesym = array("", "");
$strdone = stripslashes(str_replace($findsym,$removesym,strip_tags($string)));
$jsonarray = json_decode($strdone,true);
echo "<pre>"; echo print_r($jsonarray);
I have tried several different approaches here, but to no avail. Can someone explain to me how the following type of feed can be parsed? Below is an excerpt
<?xml version='1.0'?>
<NoticeResults xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:query>
<Notice>
<PersonId>174171199</PersonId>
<NamePrefix></NamePrefix>
<NameAdditionalPrefix></NameAdditionalPrefix>
<FirstName>Donna</FirstName>
<MiddleName></MiddleName>
<LastName>Autrey</LastName>
<NameSuffix></NameSuffix>
<NameAdditionalSuffix></NameAdditionalSuffix>
<MaidenName></MaidenName>
<City></City>
<State>IL</State>
<Country>United States</Country>
<DateEntered>2015-02-17T00:00:00</DateEntered>
<DateCompleted>2015-02-17T00:00:00</DateCompleted>
<DateExpired>2015-03-19T00:00:00</DateExpired>
<NoticeText><p><B>PEKIN </B>- Donna Lou (Morris) Autrey, 83, of Pekin passed away at 1:10 p.m. Sunday, Feb. 15, 2015, at Autumn Accolade in Green Valley.</p><p>A graveside service will be at 11 a.m. Thursday at Lakeside Cemetery. There will be no visitation. Preston-Hanley Funeral Homes & Crematory is in charge of arrangements.</p>
</NoticeText>
<NoticeType>Courtesy</NoticeType>
<Status>Active</Status>
<FromToYears></FromToYears>
<AffiliateSite>PJStar</AffiliateSite>
<AffiliateAdId>Autrey_02/17/2015_4673625</AffiliateAdId>
<PublishedBy>Peoria Journal Star</PublishedBy>
<DisplayURL>http://www.legacy.com/Link.asp?I=LS000174171199</DisplayURL>
<LocationList></LocationList>
<ShowInSpotlight>0</ShowInSpotlight>
<DateCreated>2015-02-17T01:12:37.510</DateCreated>
<RowVersion>793618506</RowVersion>
<GuestBookURL></GuestBookURL>
</Notice>
<Notice>
<PersonId>174171209</PersonId>
<NamePrefix></NamePrefix>
<NameAdditionalPrefix></NameAdditionalPrefix>
<FirstName>Lois</FirstName>
<MiddleName></MiddleName>
<LastName>Barden</LastName>
<NameSuffix></NameSuffix>
<NameAdditionalSuffix></NameAdditionalSuffix>
<MaidenName></MaidenName>
<City>Peoria</City>
<State>IL</State>
<Country>United States</Country>
<DateEntered>2015-02-17T00:00:00</DateEntered>
<DateCompleted>2015-02-17T00:00:00</DateCompleted>
<DateExpired>2015-03-19T00:00:00</DateExpired>
<NoticeText><img src="/Images/Cobrands/PJStar/Photos/C7KC6NVUW02_021715.jpg" align="left" border="0" vspace="4" hspace="10" lgyOrigName="C7KC6NVUW02.jpg"><p><B>PEORIA </B>- Lois Mae Barden, age 84, of Peoria passed away Sunday, Feb. 15, 2015, at OSF Saint Francis Medical Center in Peoria.</p><p>Lois was born on Sept. 12, 1930, in Macomb, Ill. She married James W. Barden on June 12, 1948, in Peoria. He preceded her in death in June of 1988. </p><p>She also was preceded in death by her parents and 12 siblings.</p><p>Surviving are her children, Kathy (Ted) Kindred of Manito, Ill., Lynn (Allen) Simer of Nineveh, Ind., and Jim (Deb) Barden of North Pekin, Ill.; four grandchildren; six great-grandchildren; one great-great-grandson; and her two sisters, Doris Butts and Maggie Hoyt.</p><p>Lois enjoyed spending time at home with her family. She was always there to care for them when they were in need. She also enjoyed listening to Christian music, crafting, cooking and crocheting.</p><p>A visitation will be from 1 to 2 p.m. Thursday, Feb. 19, 2015, at Davison-Fulton Woodland Chapel in Peoria. Burial will follow at Swan Lake Memory Gardens in Peoria. </p><p>Memorials may be made to Illinois Cancer Care.</p><p>Online condolences may be made through <a href="http://www.davison-fulton.com" target="_new" rel="nofollow">www.davison-fulton.com</a>.</p><center><br><a rel="nofollow" href="http://www.davison-fulton.com" target="_blank"><img src="/Images/Cobrands/PJStar/Logos/www.davison-fulton.com.jpg" border="0"></a></center>
</NoticeText>
<NoticeType>Paid</NoticeType>
<Status>Active</Status>
<FromToYears></FromToYears>
<AffiliateSite>PJStar</AffiliateSite>
<AffiliateAdId>Barden_02/17/2015_102257420</AffiliateAdId>
<PublishedBy>Peoria Journal Star</PublishedBy>
<DisplayURL>http://www.legacy.com/Link.asp?I=LS000174171209</DisplayURL>
<LocationList></LocationList>
<FHIndex>10868</FHIndex>
<FHName>Davison-Fulton Woodland Chapel</FHName>
<FHKnownByName1>Davison-Fulton Woodland Chapel</FHKnownByName1>
<FHAddressLine1>2021 North University Street</FHAddressLine1>
<FHCity>Peoria</FHCity>
<FHStateProvince>IL </FHStateProvince>
<FHZipCode>61604 </FHZipCode>
<FHPhoneNumber1>3096885700 </FHPhoneNumber1>
<FHUrl>www.davison-fulton.com</FHUrl>
<ShowInSpotlight>0</ShowInSpotlight>
<DateCreated>2015-02-17T01:13:01.857</DateCreated>
<ImageUrl>http://mi-cache.legacy.com/legacy/images/Cobrands/PJStar/Photos/C7KC6NVUW02_021715.jpg</ImageUrl>
<RowVersion>793622447</RowVersion>
<GuestBookURL>http://www.legacy.com/Link.asp?I=GB000174171209</GuestBookURL>
</Notice>
</sql:query>
</NoticeResults>
I have been banging my head against the table on this all day (huge waste of 8 hours). All we have to work with in our offices are PHP (limitation by our CMS). Can someone please explain how I would go about parsing through a feed like this? I've gotten pretty far, but still can't seem to figure this out. Please also explain why you do whatever you do in order to make this work. I'll have to parse several feeds structured this way and i've never dealt with this before. Any help will be greatly appreciated.
Thanks!
Chris
You can access the elements using DOM Extension. There is an example of looping through XML from w3schools.
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("doc.xml");
$x = $xmlDoc->documentElement;
foreach ($x->childNodes AS $item) {
// Do whatever is needed
}
?>
i am much confused at this point regarding the csv file creation and insert data in the database.
suppose i have below text data - that is of 45000 record set, i am posting dew of them below.
Winged Wheels in France, by Michael Myers Shoemaker 45790
A Battle Fought on Snow Shoes, by Mary Cochrane Rogers 45789
The German Classics of the Nineteenth and Twentieth Centuries, 45788
Volume 11, by Friedrich Spielhagen, Theodor Storm,
Wilhelm Raabe, Marion D. Learned and Ewald Eiserhardt
[Subtitle: Masterpieces of German Literature
Translated Into English]
Zofloya ou le Maure, Tomes 1-4, by Charlotte Dacre 45787
[Subtitle: Histoire du XVe si?cle]
[Language: French]
Their Majesties as I Knew Them, by Xavier Paoli 45786
[Subtitle: Personal Reminiscences of the
Kings and Queens of Europe]
[Translator: Alexander Teixeira de Mattos]
New York Times Current History: The European War, Vol. 8, 45785
Pt. 2, No. 1, July 1918, by Various
Gallery of Comicalities, by Robert Cruikshank, 45784
George Cruikshank and Robert Seymour
[Subtitle: Embracing Humorous Sketches]
Katri, by Emil Nervander 45783
[Subtitle: Kertomus 17 vuosi-sadasta]
[Language: Finnish]
The Little Brown Jug at Kildare, by Meredith Nicholson 45782
[Illustrator: James Montgomery Flagg]
Beaumont & Fletcher's Works (6 through 10), by Francis Beaumont 45781
and John Fletcher
[Subtitle: The Queen of Corinth; Bonduca; The Knight of the
Burning Pestle; Loves Pilgrimage; The Double Marriage]
Beaumont & Fletcher's Works (1 through 5), by Francis Beaumont 45780
and John Fletcher
[Subtitle: A Wife for a Month; The Lovers Progress;
The Pilgrim; The Captain; The Prophetess]
The Washington Historical Quarterly, Volume V, 1914, by Various 45779
[Editor: Edmond S. Meany]
Minstrelsy of the Scottish Border Volume III of 3, by Walter Scott 45778
[Subtitle: Consisting of Historical and Romantic Ballads,
Collected In the Southern Counties of Scotland; With
a Few Of Modern Date, Founded Upon Local Tradition.
In Three Volumes. Vol. III]
What i want is simply insert Winged Wheels in France, by Michael Myers Shoemaker in one column and 45790 in other column of CSV. then i will be able to add them to my database.
moreover, e.g,
The German Classics of the Nineteenth and Twentieth Centuries,
Volume 11, by Friedrich Spielhagen, Theodor Storm,
Wilhelm Raabe, Marion D. Learned and Ewald Eiserhardt
[Subtitle: Masterpieces of German Literature
Translated Into English]
i want to insert above text in this way:
The German Classics of the Nineteenth and Twentieth Centuries,
Volume 11, by Friedrich Spielhagen, Theodor Storm,
Wilhelm Raabe, Marion D. Learned and Ewald Eiserhardt
means no this portion:
[Subtitle: Masterpieces of German Literature
Translated Into English]
the ", by" should also omitted and so my new data would be like this. so actually i need three columns in the csv.
1 | Winged Wheels in France | Michael Myers Shoemaker | 45790
2 | The German Classics of the Nineteenth and Twentieth Centuries,
Volume 11 | Friedrich Spielhagen, Theodor Storm,
Wilhelm Raabe, Marion D. Learned and Ewald Eiserhardt | 45789
Please help in getting it inserted in excel file and create csv from it.
thank you all.
do like this
(not tested)
$f = file_get_contents('yourtextfile.txt');
$f = preg_replace('/\[(.*?)\]/s','',$f);
$f = str_replace(array("\n", "\r"), '', $f);
file_put_contents('temp.txt',$f);
$file = file('temp.txt');
foreach($file as $key => $line){
if($line!=null || $line!='')
{
mysqli_query($connection,"insert into table1(column1) values('$line')");
}
}
edit
$f = file_get_contents('tt.txt');
$f = preg_replace('/\[(.*?)\]/s','',$f);
$keywords = preg_split("/[ ]{15}/", $f);
print_r(array_filter($keywords));
i'm still not clear,whether you have those numbers in your file or you have just mentioned it there!!