How can I parse markdown inside json [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have a JSON like below format.
{
"title": "Title",
"content": "Content in **Markdown**"
}
Which could be queried if decoded as $json->title; and $json->content;,
I want to turn the content which is in Markdown to HTML,
I use Parsedown for this work.
<?php
include 'Parsedown.php';
$Parsedown = new Parsedown();
$file = file_get_contents('file.json');
$file = json_decode($file);
$Parsedown->text($file->content);
echo $file->content;
But still things appear not as expected.

If you are still not working then you are still not calling it correctly
$Parsedown = new Parsedown();
$file = file_get_contents('file.json');
$file = json_decode($file);
$file->content = $Parsedown->text($file->content);
echo $file->content;
The RESULT
<p>Content in <strong>Markdown</strong></p>

Related

PHP String Replace for BBCode [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I want to make a custom BBCode for my forum site, but I've run into an issue, and I'm having a hard time fixing it.
This is what's in the database for the body of the thread "[b]Bold[/b][i]Italic[/i][strike]Strike[/strike]".
However the output is displayed like this "[i]Italic[/i][strike]Strike[/strike]".
So, I'm guessing it's an issue with echoing it out, but i'm not sure how to fix it. Here's the current code:
function bbcode($input) {
$input = strip_tags($input);
$input = htmlentities($input);
$search = array('/\[b\](.*?)\[\/b\]/is');
$replace = array('<b>$body</b>');
return preg_replace($search, $preg_replace, $input);
}
while($row = mysql_fetch_array($threadquery, MYSQL_ASSOC)) {
$body = str_replace("\n",'<br>', $row['body']);
}
echo bbcode($body);
proper code should be:
$replace = array('<b>$1</b>');
return preg_replace($search, $replace, $input);

What does this malicious PHP do? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
My site was hacked and I found on it the
<?php
echo eval(base64_decode(str_replace('*','a',str_replace('%','B',str_replace('~','F',str_replace('_','z',str_replace('$','x',str_replace('#','d',str_replace('^','3','SOMEVERYLONGTEXT')))))))));
if I decode base64 without executing, I got some script, starting with:
$__authentication_pass = "52b1d005abc139cc281a32d8aa7cd1c2";
$color = "#df5";
$__default__action = 'FilesMan';
$default_use_ajax = true;
$default_charset = 'Windows-1251';
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
$userAgents = array("Google", "Slurp", "MSNBot", "ia_archiver", "Yandex", "Rambler");
if (preg_match('/' . implode('|', $userAgents) . '/i', $_SERVER['HTTP_USER_AGENT'])) {
header('HTTP/1.0 404 Not Found');
exit;
}
}
#ini_set('error_log', NULL);
.... and many lines below ....
I this file manager? Can it be identified somehow (name, author and so on)?

json decode from "{" and "[" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Im trying to json_decode the following:
"main":{
"temp":9.04,
"temp_min":9.04,
"temp_max":9.04,
"pressure":938.13,
"sea_level":1037.57,
"grnd_level":938.13,
"humidity":87
},
"weather":[
{
"id":801,
"main":"Clouds",
"description":"few clouds",
"icon":"02d"
}
],
$result = json_decode($json);
$temp = $result->main->temp; //is displaying the data
however
$id = $result->weather->id; //is not displaying anything
all i can see is difference that te second one have an extra "[]"
can you help me telling how can i get weather->id from that json, thank you
The weather element is an array: it contains a list of elements. To get what you want from that exact example you would want:
$id = $result->weather[0]->id;
You also might want to think about what you want to happen if there is more than one element in that array, or if there are zero.

simplexml_load_file() with a variable [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I'm currently having an issue with simplexml_load_file(); my xml path is a url, that is rendered as a variable
$xurl = "domain/pathto/myfile.xml"; // This is actually a variable that returns the entire URL to where my xml file is -- this will change from file to file
$xmlpath = parse_url($xurl, PHP_URL_PATH); // to get the path of my xml file ex. /pathto/myfile.xml
$xmlpath = mb_substr($xmlpath, 1); // returns pathto/myfile.xml
here is where my problem is, when I put it into :
simplexml_load_file($xmlpath);
In my function, I get nothing appearing from the XML file
However, in my same function if I change it to
simplexml_load_file("pathto/myfile.xml");
My function works fine.
I did an echo on $xmlpath and it returns the pathto/myfile.xml just fine.
<?php echo $xmlpath; ?> // returns pathto/myfile.xml
What am I doing wrong?
EDIT: Phil
echo strcmp("pathto/myfile.xml", $xmlpath)
returns a 0.

Can you do a $json = file_get_contents($url); within a foreach statment already using $json = file_get_contents($url);? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Improve this question
$url = "www.test.com"
$json = file_get_contents($url);
$data = json_decode($json);
foreach($data as $mydata) {
$id = $mydata->id;
$url2 = "www.test.com/$id";
$json2 = file_get_contents($url2);
$data2 = json_decode($json2);
var_dump($data2); // seems to always be null?? :(
foreach($data2 as $mydata2) {
.............
}
}
the error I get is Warning: Invalid argument supplied for foreach() which is because data2 is not an array....
Guessing I can't do file_get_contents() stacked like I am. Is there a way around this?
First check, is your url return a JSON? If yes then you can use following instead
$data = json_decode($json, TRUE);
The TRUE returns an array instead of an object.
URL isn't returning valid JSON.

Categories