I am working with php and i am trying to get data from "Editor" ( like Tinymyc),But
right now i am getting special characters like "<strong> ,<p>" etc..i just want to get simple data
without any special characters,how can i do this ?I tried with following code
$data=$_POST['editor'];
Give this a try - if your code is correct this should work.
$data = strip_tags($_POST['editor']);
Related
I have the following in my categories table. There are Russian symbols present:
id name
1 Обувь
Обувь = Obuv
I'm looking to get "Obuv" as Russian symbols within the output.
echo Category::select('name')->first();
This script should give me "Обувь" as the output, but I'm getting
{"name":"\u041e\u0431\u0443\u0432\u044c"}
What's wrong? How can I get the correct output? If I write "Obuv" in the database, the english "Obuv" will give me the correct output in Laravel. In phpMyAdmin, it gives me Russian symbols without trouble. The problem lies in Laravel.
You are outputting the data by echoing your Category model which outputs in JSON by default in Laravel. This automatically escapes multibyte Unicode characters upon output by default. When you run json_encode(), you could supply the JSON_UNESCAPED_UNICODE option like so:
$data = Category::select('name')->first();
echo json_encode($data, JSON_UNESCAPED_UNICODE);
I should be clear, though. Your Category does not have the escaped data stored within it, the escaping only takes place when you output to JSON. If all you were doing is ensuring you got the correct data back from the database by echoing it, you should be in the clear.
If you're looking for just the raw text of the category's name property, you should be able to output this like so:
echo $data->name;
For more information, see http://php.net/manual/en/function.json-encode.php and https://laracasts.com/discuss/channels/laravel/how-to-prevent-laravel-from-returning-escaped-json-data.
I'm trying to create a simple blog type system for my site using PHP and MYSQL.
everything works fine. however, the issue that I am facing right now is that when I insert data into mysql database, it will have some extra characters.
the extra character that I am having the most difficulty with is this: \
Example:
when I insert an image link/tag into database: I get the following in my database:
<p><img alt=\"\" src=\"http://somedomain.com/images/9Image1.jpg\" /></p>
so I am trying to remove those extra characters before inserting the data into mysql using PHP.
for that, I tried using the following code:
$body = preg_replace("/\\\\\/", "", $body);
however, this code doesn't do anything. and in fact stops my entire code working and it stops my code from inserting any data into mysql.
Could someone please advise on this issue?
Thanks in advance.
Try to use stripslashes(string)
$body = stripslashes($body);
Let me know if it works.
I am using laravel 4.2 and I am having a very weird problem while saving the data using the model.
I have a text area where user inputs some text and then hit the save button. it is saving fine when the text does not have any quotes in it. But gives issues when the text have some quotes.
For example: If I try to save "Hi. I am Jacky's friend." This text saves fine but when I check in the database there I see this "Hi. I am Jacky\\\'s friend." I get extra back slashes saved in the database.
This is my code :
Suppose $textnotes is the variables in which I am getting the entire text.
$savenotes = new Details(); // Details is the model and the table name is 'Details'
$savenotes->Notes = $textnotes; // 'Notes' is the column
$savenotes->save();
if(!empty($savenotes->id))
// My other stuffs here
I am unable to fix this. Any help will be appreciated.
This could be a PHP setting called Magic Quotes interfering with strings when they contain certain characters, rather than a Laravel specific problem. You can turn this off in your php.ini file, by following instructions in the documentation.
I currently working on PHP and at some part of code I generate URL string. I set the GET parameter to currencyCode. But before I add &. So, at result I must get ¤cyCode but get ¤cyCode.
How do I fix it?
You need to create url this way using urlencode() function:
<?php
echo 'http://example.com/'.urlencode('¤cyCode');
I also think that your main problem is with displaying it. You should use:
echo htmlspecialchars('¤cyCode');
to display it.
Otherwise it seems browser change the first part of this string into: ¤ entity so you get something like that ¤cyCode and what makes you have display ¤ symbol what is ¤ and the rest of string cyCode
You should use urlencode() function in php to encode the url. Your code should look like this
<?php
echo 'http://yoursitename.com/'.urlencode('¤cyCode');
I am trying to insert into mysql from an xml using PHP, but the field name contains a "hyphen" and for some reason it is not inserting this field, the rest are fine. I have tried using the hex codes x002D, x2010,x2012, and none have worked. As you can see in my xml, the hyphen is not being changed like the space, but if I just remove the x002D inserts everything after the "E" in other words just inserts -mail_x0020_Address.
This is my xml:
<encuestas>
<ID>9949</ID>
<E-mail_x0020_Address>email#email.com</E-mail_x0020_Address>
<ZIP_x002F_Postal_x0020_Code>90001</ZIP_x002F_Postal_x0020_Code>
</encuestas>
This is my insert statement ( I removed fields, I have 20 on that xml):
"INSERT INTO New_Encuestas_Datos(ID,`email`,`Zip/Postal Code`) VALUES('$product->ID','$product->E-mail_x0020_Address','$product->ZIP_x002F_Postal_x0020_Code')";
The variables are coming from an array reading the xml and like I said, everything is imported except email. I have tried the following combinations:
E-mail_x0020_Address
E_x002D_mail_x0020_Address
E_x2010_mail_x0020_Address
E_x2012_mail_x0020_Address
Can anyone point me what I am doing wrong? Thanks !
Hmm, I doubt you can use it in a string, but in plain PHP it is $product->{'E-mail_x0020_Address'};. But that doesn't matter anyway, as you should escape you values prior to sending them to a database you can nicely name an escaped variable as you like.
Try using:
"INSERT INTO New_Encuestas_Datos(ID,`email`,`Zip/Postal Code`) VALUES('{$product->ID}', '{$product->E-mail_x0020_Address}', '{$product->ZIP_x002F_Postal_x0020_Code}')";
Edited:
Just found here Validate class/method names with regex that '-' is not valid in method names.