PHP if / while和/或img调整大小错误 [英] PHP if/while and or img resizing error

查看:104
本文介绍了PHP if / while和/或img调整大小错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编码器。我很新的PHP,所以我的代码可能是错误的,因为它得到。
Im从txt文件中加载纯文本并使用它从网站加载图片。 (感谢这个论坛帮助我)。现在即时通讯有调整这些照片的问题。首先,我不认为我在最后2点得到了if语句,我真的不知道如何使用while,如果我甚至不得不使用它。

你可以查看代码并查看是否有任何错误?谢谢。



在第一个(if)部分中,我将txt文件中的文本转换为图像。现在我想调整所有这些图像。在第二(如果)即时尝试调用所有这些图像进行调整。在第三个(如果)即时试图调用所有这些调整大小的图像,所以我可以在最后一位代码中回显他们。

  <?php 

$ file ='serverlist.txt';
$ servers ='';
if($ handle = fopen($ file,'r')){
while(!feof($ handle)){
$ content = trim(fgets($ handle));
$ names = explode('',$ content);
foreach($ names as $ name){
$ servers。='< img src =http://minecraft.net/skin/'。$ name。'.pngalt = >';
}
}
fclose($ handle);
} else {

}
if $ file =='serverlist.txt'{
$ fullimages = explode($ servers);
foreach($ fullimages as $ _fullimages){
$ face = imagecreatetruecolor($ width,$ height);
$ imgwidth = 200;
$ imgheight = 200;
imagecopyresized($ face,$ _fullimages,0,0,8,8,$ width,$ height,8,8);
imagecopyresized($ face,$ _fullimages,0,0,40,8,$ width,$ height,8,8);

} else {

}
if $ file ='serverlist.txt'{
$ displayimages = explode($ _ fullimages);
foreach($ displayimages as $ _displayimages){
$ b}
} else {

}
echo $ _displayimages;
?>


解决方案

c> if 语句应该使用 == 而不是单个 =

 <?php 

$ file ='serverlist.txt';
$ servers ='';
if($ handle == fopen($ file,'r')){
while(!feof($ handle)){
$ content = trim(fgets($ handle)) ;
$ names = explode('',$ content);
foreach($ names as $ name){
$ servers。='< img src =http://minecraft.net/skin/'。$ name。'.pngalt = >';
}
}
fclose($ handle);
} else {

}
if($ file =='serverlist.txt'){
$ fullimages = explode($ servers);
foreach($ fullimages as $ _fullimages){
$ face = imagecreatetruecolor($ width,$ height);
$ imgwidth = 200;
$ imgheight = 200;
imagecopyresized($ face,$ _fullimages,0,0,8,8,$ width,$ height,8,8);
imagecopyresized($ face,$ _fullimages,0,0,40,8,$ width,$ height,8,8);

} else {

}
if($ file =='serverlist.txt'){
$ displayimages = explode($ _ fullimages) ;
foreach($ displayimages as $ _displayimages){
$ b}
} else {

}
echo $ _displayimages;
?>


coders. Im very new to php, so my code is prob as wrong as it gets. Im loading plain text from a txt file and useing that to load pictures from a website. (Thanks to this forum for helping me with that). Now im having problems with resizing those photos. First of all, i dont think i got the if statement right on the last 2. and i dont really know how to use "while", and if i even have to use it.

Can you look over the code and see if you see any mistakes? Thank you.

In the first (if) section i made the text in the txt file to images. Now i want to resize all those images. In the second (if) im trying to call all those images to be resized. In the third (if) im trying to call all those resized images so i can echo them in the last bit of code.

<?php

$file = 'serverlist.txt';
$servers = '';
if ($handle = fopen($file, 'r')) {
    while (!feof($handle)) {
        $content = trim(fgets($handle));
        $names = explode(' ', $content);
        foreach ($names as $name) {
            $servers .= '<img src="http://minecraft.net/skin/' . $name . '.png" alt="">';
        }
    }
    fclose($handle);
} else {

}
if $file == 'serverlist.txt' {
    $fullimages = explode($servers);
    foreach ($fullimages as $_fullimages) {
        $face = imagecreatetruecolor($width, $height);
        $imgwidth = 200;
        $imgheight = 200;
        imagecopyresized($face, $_fullimages, 0, 0, 8, 8, $width, $height, 8, 8);
        imagecopyresized($face, $_fullimages, 0, 0, 40, 8, $width, $height, 8, 8);
    }
} else {

}
if $file = 'serverlist.txt' {
    $displayimages = explode($_fullimages);
    foreach ($displayimages as $_displayimages) {

    }
} else {

}
echo $_displayimages;
?>

解决方案

You are asigned the values in every if statement you should use == instead of single =

<?php

    $file = 'serverlist.txt';
    $servers = '';
    if ($handle == fopen($file, 'r')) {
        while (!feof($handle)) {
            $content = trim(fgets($handle));
            $names = explode(' ', $content);
            foreach ($names as $name) {
                $servers .= '<img src="http://minecraft.net/skin/' . $name . '.png" alt="">';
            }
        }
        fclose($handle);
    } else {

    }
    if ($file == 'serverlist.txt') {
        $fullimages = explode($servers);
        foreach ($fullimages as $_fullimages) {
            $face = imagecreatetruecolor($width, $height);
            $imgwidth = 200;
            $imgheight = 200;
            imagecopyresized($face, $_fullimages, 0, 0, 8, 8, $width, $height, 8, 8);
            imagecopyresized($face, $_fullimages, 0, 0, 40, 8, $width, $height, 8, 8);
        }
    } else {

    }
    if ($file == 'serverlist.txt') {
        $displayimages = explode($_fullimages);
        foreach ($displayimages as $_displayimages) {

        }
    } else {

    }
    echo $_displayimages;
    ?>

这篇关于PHP if / while和/或img调整大小错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆