data: disappears from base64 string - php

I have a base64 image that i need to display via php.
It's to be used on a wordperss/woocommerce site, at the cart.
The string is correct and working fine when inserting directly into plain html img tag.
The string starts as such: data:image/png;base64...............
But when it's inserted as src, via php, it doesn't include the beginning "data:" word.
It displays as: image/png;base64...............
I have tested the string with plain echo, and it does include data: when just echoed out, but as soon as it's palced inside src or href, data: goes away.
I have no idea why this is happening and search results in no meaningful information.
Added code snippet:
$img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAAImCAYAAACrXu7BAAAgAE................";
echo '<img src="'.$img.''" />';
data: disappears, echoes out as:
<img src="image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAAImCAYAAACrXu7BAAAgAE................" />
But if i do this:
$img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAAImCAYAAACrXu7BAAAgAE................"
echo $img;
It works and echoes as:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAAImCAYAAACrXu7BAAAgAE................

I found the issue.
It was indeed wordpress/woocommerce that was the issue, specifically in the cart and not syntax errors...
The issue is do to: wp_filter_post_kses
I will mark this as resolved...
Thanks to those who actually tried to help and understand that the code snippet was not the real code and that there was no syntax errors, as i stated.
Maybe people should not be overly pedantic when trying to help? Just a thought...

Related

PHP not reflecting desired HTML

I'm making a website where a user should be able to use HTML and CSS in their profiles but I came across one problem.
<?php
$profile = "<h1>THIS IS A TEST</h1>";
echo htmlentities($profile);
?>
That's my code, but it only show this in the profile:
<h1>THIS IS A TEST&amp</h1>
I don't know what is happening, nor do I know if this only happens to me.
How do I make it show only the h1 content?
Function htmlentities is showing the representation of html characters like tags etc., and is being used especially to avoid parsing as html. So if you mean to echo html so that the browser parses it as html, the last thing you want is to use this function! Just echo it out directly, no need to use htmlentities or htmlspecialchars!
You just have to use echo $profile;, that's all. Check this and don't forget to check Display as HTML as browsers display PHP echoed text as HTML unless they're told to display it differently.

Why does my browser display the encoded html entity (e.g. &amp;amp;amp;)?

I have a php page that displays customer's input, which I saved in mysql database. When the input is loaded, some html characters are displayed wrongly.
For example this url:
http://www.greenbook.club/shopjerry/index.php/014101201323
You can see that the browser actually displays & amp; not just &.
I tried to use htmlspecialchars_decode or html_entity_decode, but seems no impact.
The code is really basic, just:
<?php echo $description ?>
////I also tried this, but no difference
<?php echo html_entity_decode($description) ?>
Can someone help?
I'd be looking at how this data is being saved. It appears that it's being encoded each time it's being saved without being decoded.
If you look at the rogue codes ie can&amp;amp;#39;t which is originally the word can't.
On the first save the single quote in can't would be getting turned into '
On the Second save that would then turn into &#39; then &amp;#39 and so on for each save.
SO the issue is with the process of saving the content from the editor into the Database. The content is being encoded when saved to the DB from the Editor but not decoded when loaded back from the DB into the editor.

Text in <textarea> automatically getting tabbed in

pretty new to Mysql, HTML and PHP and I can't seem to find much information on this trouble i'm having.
I Am making my own rough project manager type thing and I have a form that lets me change the contents of each individual change log, the problem I have however is that when I load the data in to the text area it start with a big indentation at the start, like 3-4 tabs inwards. I would attach an image but I need at least 10 rep to do that.
Basically, it feels like the data in the database has tabs or something at the start of it, but when I go to look in PHPmyadmin at the field, it just looks like it should do, not tabbed at all.
I've tried using strip_tags() but I think it only works on visible tags.
Does any1 know how to get rid of this or what is causing the problem?
I'll be following this question closely to see if anybody can provide an answer because I'm stumped.
Thanks,
Try to echo your php code with no blanks :
Possible tabs, bad example :
<textarea>
<?php echo $tabContent; ?>
</textarea>
Avoiding tabs :
<textarea><?php echo $tabContent; ?></textarea>
You can also try to trim your php content like that :
<textarea><?php echo trim($tabContent); ?></textarea>
Try doing var_dump and look how long your queried string is.
If it is as long as in your database you problem is within the textarea.
Is there any css you use with textarea?

Echo doesn't show copy-pasted text from txt file to form text area PHP

This is maybe a stupid problem to solve but i've looked around and i can't manage to find a viable solution.
I'm making a simple form where:
the user write some text into text-areas
the php must echo back those data into a simple html code to copy it somewhere else
something like this: http://www.w3schools.com/php/showphp.asp?filename=demo_form_validation_complete
but there is a problem even in the demo from w3schools: when i have some text into a *.txt file or another web page/local document and i copy(or cut) and paste it into the form and send to receive the echo it sends back a "null" value from the variable, while it doesn't happen when i type into it.
How can i solve this? Is there a way to send to the variable a copy-pasted text instead of a "null" value?
You may have an apostrophe in the copied text and it's being converted into a curled apostrophe (see: http://www.dwheeler.com/essays/quotes-in-html.html). If you're just echoing it back out to the screen, you could wrap the $_POST['content'] in a htmlentities().

How do I mix php inside php strings?

I'm trying to mix <?php echo do_shortcode('[...]') with a field from Advanced Custom Fields within Wordpress.
So basically what I'm trying to do is give the user a text field in the page edit screen where she can paste in the ID of a youtube vide. This field will then update my do_shortcode to display the correct video.
I'm not sure what I'm doing wrong considering I've done this several times before and been succesful. I do have a feeling I'm not escaping the string correctly?
<?php echo do_shortcode('[video_lightbox_youtube video_id="' . the_field("youtube_video") . '" width="640" height="480" anchor="Play Video"]'); ?>
Anyone able to lead me in the right direction? :)
EDIT
The code above returns q_cHD1lcEOo with multiple spaces in front of it as well as this: "Error! You must specify a value for the Video ID, Width, Height parameters to use this shortcode!" That's why I was thinking I'm not escaping it correctly as these are all specified.
I'll add that if I remove the_field("...") and replace it with just an ID it displays perfectly.
SECOND EDIT
Since I was not supposed to echo it, I was using the wrong function to get the field. Instead of using the_field() which prints the value, I was supposed to use get_field() to simply return it to the string.
Your question is somewhat unclear, but I'm also 20 hours without sleep.
Anyways, as far as mixing PHP within a PHP string, there's numerous ways to do it..
You can use concatenation or { } within the string itself.
For example, say we want to echo out the property of an object within a string.
We could do the following
echo "This is my property " . $object->property;
Or, we can do this
echo "This is my property {$object->property}";
You can even do cool things like access associative arrays within strings like so
echo "This is my property {$object->property['cool']}";
Hopefully this leads you in the ride direction.
At first glance it looks like you should be using get_field instead of the_field. the_field will print without being prompted, whereas get_field will return its value, which is what you want.
I see you've also mentioned whitespace at the start, you should consider wrapping the function in trim.
See below:
<?php echo do_shortcode('[video_lightbox_youtube video_id="' . trim(get_field("youtube_video")) . '" width="640" height="480" anchor="Play Video"]'); ?>

Categories