convert plaintext to html on PHP - php

I'm using a php frameworks based on (Yii) , my problem is when I insert an html code to my input text after submit I get a plaintext but i want to get is the html format
example
<img src="https://example.com/ex1/ex1.jpg" border="0"> <img src="https://example.com/ex2/ex2.jpg" border="0">
What I get is text with link to the images
<img src="https://example.com/ex1/ex1.jpg" border="0"> <img src="https://example.com/ex2/ex2.jpg" border="0">
my desired output is images not text with link, I used
html_entity_decode(htmlentities($content)); // not working
html_entity_decode($content); // not working
htmlspecialchars_decode($content); // not working too
nl2br($content); // also not working
the output is in the variable content
<div class="content" id="wall_content_<?= $object->getUniqueId(); ?>">
<?= $content; ?> </div>
THANK YOU

Related

How to pass a variable/change html from php

So I'm using PHP to grab my profile picture from my steam profile and i want to display it on the page is there any way to pass the variable containing the picture to html or edit my html code from PHP???
here is my code
<?php
$pic_path = file_get_contents("http://steamcommunity.com/id/LocalSugarDaddy");
preg_match('/<div class="playerAvatarAutoSizerInner"><img src="(.*)" \/><\/div>/i', $pic_path, $pic);
?>
I guess you are trying to use PHP variable containing image URL and want to use in html tag. If so, then you can do below:
<?php
$your_picture_str = "http://www.domainname.com/picture_url.jpg";
?>
<div><img src="<?php echo $your_picture_str; ?>" width="100%" alt="" title="" /></div>

Extra url getting appended in image source

<img src="https://ci3.googleusercontent.com/proxy/B66o0CPxJoqxeKiWDOzMp3n5nsNJ6Tcemt3sHrZ0C5SXqLtZg0hc0z9U8jo=s0-d-e1-ft#http://images/ayay.png">
When I am uploading an image this extra part
OUTPUT:
https://ci3.googleusercontent.com/proxy/B66o0CPxJoqxeKiWDOzMp3n5nsNJ6Tcemt3sHrZ0C5SXqLtZg0hc0z9U8jo=s0-d-e1-ft#
is coming in src part of image.
What it that i am doing wrong?
SEPARATE PHP FILE(From here I fetch (imageame)
function sendimg($id,$filename){
$_SESSION['image_name']=$filename;
}
HTML CODE
<div id="wer">
<img src="images/<?php echo $_SESSION['image_name'].'.png';?>"
</div>

Display an image stored in mySQL database with PHP

I have a database which contain blob images. I want to display them in a webpage. I'm using the following php code to get the image. But it didn't work properly.
<?php
while($row=mysql_fetch_array($results))
{?>
<tr>
<td><img src="<?php echo $row["image"]?>" height="200" width="250"></td>
</tr>
<?php
}?>
With this code I'm getting a webpage like this.
Where I have to do the correction to my code.
try to convert it to base64:
<img src="data:image/jpeg;base64,<?php echo base64_encode($row['image']); ?>" height="200" width="250">
Note that you should also store the image type in your DB, so you can dynamically change "data:image/jpeg".

Error displaying blob image in php/html

I am trying to display image from a blob field of a MySQL table. Looks like I have some sort of error in the following line. As soon as I put "header("Content-type: image/jpeg")" things get messed up and instead of displaying webpage, all source code of the page is displayed.
Please let me know how to correct.
<div class="image" align="left">
<a href="<?php header("Content-type: image/jpeg"); echo $rec['image']; ?>">
<img src="<?php echo $rec['image']; ?>" width="150" border="0"/>
</a>
</div><!-- image -->
You normally don't put the actual image contents in the src= attribute of the image tag. Instead, you point to the URL of an image file.
(There are ways to include the image source directly in the HTML, but it doesn't work consistantly with all browsers, and you still won't have your <a> link working properly.
Instead, the best way to do this is to create a separate PHP file to serve the image.
Your HTML:
<div class="image" align="left">
<img src="myimage.php?key=<?php echo($key) ?>" width="150" border="0"/>
</div><!-- image -->
myimage.php:
<?php
header("Content-type: image/jpeg");
$key = $_GET['key'];
// todo: load image for $key from database
echo $rec['image'];
You're trying to put the image data inline inside the content. The only feasible way to do this is via a Data URI data URI. Something like:
<img src="data:image/jpeg;base64,<?= base64_encode($rec['image']) ?>" width="150" border="0" />
However, what you probably want to do is put it into a separate script. So your HTML would be:
<img src="showimage.php?id=XXX" width="150" border="0" />
And your showimage.php script would be:
<?php
// Get $rec from database based on the $_GET['id']
header('Content-Type: image/jpeg');
echo $rec['image'];
?>
I've done something like that retrieving blob from my database in another way that you may find useful, here is the code example.. see if it suits your needs and if you needed anymore help let me know.
while ($row = mysql_fetch_array($hc_query2)) {
$title = $row['title'];
$text = $row['text'];
$image = $row ['image'];
$output ='<div class="HCInstance"><img src="data:image/jpeg;base64,' . base64_encode($image) . '" alt="High Council" width="100px" height="100px"/>
<div class="HCHeader"><h2>'.$title.'</h2></div><br/><div class="HCDetails"><p>'.$text.'</p></div></div>';
echo $output;
}

make array object in for loop with horizontal view

<?php
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=London');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
<head>
<title>Google Weather API</title>
</head>
<body>
<h1><?php print $information[0]->city['data']; ?></h1>
<h2>Today's weather</h2>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
<span class="condition">
<?php echo round(conver_f_c($current[0]->temp_f['data'])); ?>° C,
<?php echo $current[0]->condition['data'] ?>
</span>
</div>
<h2>Forecast</h2>
<?php foreach ($forecast_list as $forecast) : ?>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
<div><?php echo $forecast->day_of_week['data']; ?></div>
<span class="condition">
<?php echo round(conver_f_c($forecast->low['data'])); ?>° C - <?php echo round(conver_f_c($forecast->high['data'])); ?>° C,
<?php echo $forecast->condition['data'] ?>
</span>
</div>
<?php endforeach ?>
</body>
</html>
<?php
function conver_f_c($F){
return $C = ($F − 32) * 5/9;
}
I want Out somthing like this manner of the horizontal ,
Even i tried UL LI WITH display inline but it goes failed,
Tell me some good suggestion for my probme,
I want exactly like horizontal, expecting exactly like screen shot ,
Tell me How to render using php
Thanks
alt text http://img163.imageshack.us/img163/7518/weatherhori.jpg
Above snippet present display out verticly , i want o change that verticle to horizonatal ,
somthing like this screen shot
<table>...</table>
Update
From your latest comment so far:
i know how to fetch array and display
it, but i dont know to fetch and
display in the verticl manner that is
the stuck up
I feel this is going to be a stupid answer but it appears to be what you don't understand...
The web is based in a markup language called HTML. This language has tags (delimited by angle-brackets) that allow you to define the structure of a document. On top of this, you have another language called CSS. This other lang allow you to define how HTML is going to be displayed on screen.
You may argue that you already have a web page and you've written it with the PHP language instead of the two other langs I've mentioned. That's not enterely true: you code in PHP, sure, but you use PHP to generate HTML. And it's HTML what finally reaches the browser (Firefox, Explorer...). PHP is executed in the web server, not in the browser. The browser can only see whatever HTML you've generated.
To sum up: you have to forget about PHP, Google and the whole weather thingy. You first need to write a static HTML document and style it with CSS. Once you've done with it, you can finally replace the parts of the information that are dynamic with values taken from your PHP variables.
And since you seem to need a table to display tabular data, the appropriate HTML tag is <table>:
<table>
<tr>
<th>Web</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
<td><img src="/path/to/pics/sunny.png" width="25" height="25" alt="Sunny"></td>
<td><img src="/path/to/pics/rainy.png" width="25" height="25" alt="Rainy"></td>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
</tr>
<tr>
<td>26ºC</td>
<td>26ºC</td>
<td>22ºC</td>
<td>25ºC</td>
</tr>
<table>
I suggest you find some tutorials about basic HTML and CSS. They'll be of invaluable help.
This is what's done by Google :
http://jsfiddle.net/bW8NA/1

Categories