Click here to Skip to main content
14,424,083 members

Resize width and height of images

Member 14174664 asked:

Open original thread
I have content stored in mysql, as following: 


<table width="210" cellspacing="1" cellpadding="1" border="0">
    <tbody>
        <tr>
            <td><img width="513" height="680" align="left" alt="" src="/userfiles/image/pic.jpg" /></td>
            <td><img width="315" height="700" align="left" alt="" src="/userfiles/image/DSC_0389.JPG" /></td>
            <td><img width="580" height="320" align="left" alt="" src="/userfiles/image/ktxh.jpg" /></td>
        </tr>
    </tbody>
</table>



When I load from db, PHP and display in html by PHP, there is no problem.

The $content it be read from mysql($child_article[6]) and display in html by dynamic code:

$sql_article = "select * from articles where approved=1 order by timestamp DESC"; @$childResult_article = general_query($sql_article); 
if ($child_article = mysql_fetch_row($childResult_article)) 
echo decode_data($child_article[6]). 


Now, I want all images, be displayed by fixed width and height as 200 X 200 AND TABLE BORDER = '0' ($content load from mysql by php and replace width and height of all images by 200 x 200 then echo $content to website)


What I have tried:

i tried, but can't result: 

$newWidth = 200; 
$newHeight = 200; 
$content = preg_replace( array('/width="\d+"/i', '/height="\d+"/i'), array(sprintf('width="%d"', $newWidth), sprintf('height="%d"', $newHeight)), $child_article[6]); 



How do I solve this problem?
Tags: PHP, MySQL

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100