Jump to content

Recommended Posts

Hi, I have an interactive blog where users can post information via mysql database. I ran into a problem today though when someone used what im assuming was html to post some images. Now I am all for the use of images as well as html in the posts like this however the space where data is displayed is only about 600 pixels in width, but the image they posted was almost twice that size so the image spilled into my navigation column and basically screwed up the look of the page.

 

My question is: Is there a way to control the size of posts like this so that they will be resized to fit the column that they are displayed in?

 

my current display code:

<?php

require_once('load_data.php');

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die('<strong style="color:maroon">Sorry, database undergoing maintenance. Please try again later.</strong>');

if (!mysql_select_db($database))
    die("Can't select database");

$result = mysql_query("SELECT * FROM $table WHERE date BETWEEN UNIX_TIMESTAMP(DATE_SUB( CURDATE( ) ,INTERVAL 5 DAY )) and UNIX_TIMESTAMP( ) ORDER BY id DESC")or die(mysql_error());

while($row = mysql_fetch_array($result))
{
 $subject = $row['col_2'];
  	echo '<div class="job_posts">';
  	echo '<h2>';
  	echo '<a href="position.php?id='.$row['id'].'" class="job_link">'.stripslashes(htmlspecialchars($row['col_4'])).'</a>';
  	echo '</h2>';
  	echo '--<em>';
  	echo '<a href="user.php?id='.urlencode($subject).'" title="recent posts by '.$row['col_2'].'">'.stripslashes(htmlspecialchars($row['col_2'])).'</a>';
    echo '</em>   ';
    echo date("M dS, Y", $row['date']);
    echo '<p>';
    echo stripslashes(substr($row[col_5],0,350)).' <strong><a href="position.php?id='.$row['id'].'">Read more >></a></strong>';
    echo '</p>';
    echo "</div>";
    
}
mysql_free_result($result);
?>

Link to comment
https://forums.phpfreaks.com/topic/166731-solved-define-dimentions-of-html-data/
Share on other sites

Humm..

i don't like this solution but with your system being so open i guess it may work

//replace images with a prefixed height or width
$html = preg_replace('/<img.*?src=(["\']?)(.*?)\1.*?>/', '<img src="\2" height="100px">', $html);

 

the correct solution is to not allow HTML but use BBcode instead

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.