div and class not showing up - php

I'm testing a barcode on my website but for some reason the div with the class="b128" which stands for the barcodes is not showing up. If I test the same source code on another website it does show up but with different styling.
Does anyone know how I can make this source code show up and keep the original styling at the same time?
<style>
div.b128{
border-left: 1px black solid;
height: 60px;
}
</style>
<?php
global $char128asc,$char128charWidth;
$char128asc=' !"#$%&\'()*+,-./0123456789:;<=>?#ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$char128wid = array(
'212222','222122','222221','121223','121322','131222','122213','122312','132212','221213', // 0-9
'221312','231212','112232','122132','122231','113222','123122','123221','223211','221132', // 10-19
'221231','213212','223112','312131','311222','321122','321221','312212','322112','322211', // 20-29
'212123','212321','232121','111323','131123','131321','112313','132113','132311','211313', // 30-39
'231113','231311','112133','112331','132131','113123','113321','133121','313121','211331', // 40-49
'231131','213113','213311','213131','311123','311321','331121','312113','312311','332111', // 50-59
'314111','221411','431111','111224','111422','121124','121421','141122','141221','112214', // 60-69
'112412','122114','122411','142112','142211','241211','221114','413111','241112','134111', // 70-79
'111242','121142','121241','114212','124112','124211','411212','421112','421211','212141', // 80-89
'214121','412121','111143','111341','131141','114113','114311','411113','411311','113141', // 90-99
'114131','311141','411131','211412','211214','211232','23311120' ); // 100-106
////Define Function
function bar128($text) { // Part 1, make list of widths
global $char128asc,$char128wid;
$w = $char128wid[$sum = 104]; // START symbol
$onChar=1;
for($x=0;$x<strlen($text);$x++) // GO THRU TEXT GET LETTERS
if (!( ($pos = strpos($char128asc,$text[$x])) === false )){ // SKIP NOT FOUND CHARS
$w.= $char128wid[$pos];
$sum += $onChar++ * $pos;
}
$w.= $char128wid[ $sum % 103 ].$char128wid[106]; //Check Code, then END
//Part 2, Write rows
$html="<table cellpadding=0 cellspacing=0><tr>";
for($x=0;$x<strlen($w);$x+=2) // code 128 widths: black border, then white space
$html .= "<td><div class=\"b128\" style=\"border-left-width:{$w[$x]};width:{$w[$x+1]}\"></div>";
return "$html<tr><td colspan=".strlen($w)." align=center><font family=arial size=2><b>$text</table>";
}
?>
<?php
$test = "12345";
echo '<div style="border:3px double #ababab; padding:5px;margin:5px auto;width:135px;">';
echo bar128(stripslashes($test));
echo '</div>';
?>

You aren't closing most of your tags. Try this:
$html = "<table cellpadding=0 cellspacing=0><tr>";
for ($x = 0; $x < strlen($w); $x += 2) // code 128 widths: black border, then white space
$html .= "<td><div class=\"b128\" style=\"border-left-width:{$w[$x]};width:{$w[$x+1]}\"></div></td>";
return "$html</tr><tr><td colspan=" . strlen($w) . " align=center><font family=arial size=2><b>$text</b></font></td></tr></table>";

Related

which one is better for checking images? php or js

I need to check images of contents on website.
I wrote code use php that doesn't have a problem, but I found some different ways on internet(Click to see example!)
from your opinion which is more efficient?
My website template seems like this: https://imgur.com/XOdDEZu
below is my php code :
$random_img = rand(1,9); // I have saved images to folder img_1, img_2 ...
$fixed_image = "<img src='public/img/duz/img_".$random_img.".jpg' style='width: 100%; height:320px; filter: blur(.1rem);' border:2px solid red;>";
$uploaded_img_file = "public/upload/$value->content_img";
$img_url = $value->content_img;
$find_letters = array('jpg', 'jpeg', 'png','gif','svg');
$match = (str_replace($find_letters, '', substr($img_url,-4)) != substr($img_url,-4));
//true if the last 4 characters of img url match the 4 characters in the array; returns false if it does not match
if (empty($value->content_img)) {
echo $fixed_img;
echo $a;
}elseif (file_exists($uploaded_img_file)) {
echo "<img src='".$uploaded_img_file."'>";
//print_r($uploaded_img_file);
}elseif (strlen($img_url)>=3) { //If the string length of the data from the database exceeds 3 characters. (no image if less than three characters)
if (filter_var($img_url, FILTER_VALIDATE_URL) !== false && $match==true) { //url validation check
echo "<img src='".$img_url."'>";
}else{
echo $fixed_img;
$String_title = $value->content_title;
$title_limit = limit_text($String_baslik, 10);
echo $a;
}
//print_r($img_url);
}else{
echo $fixed_img;
echo '<div style="position:absolute; left:15px; bottom:5px; text-decoration: none;"><span>Merhaba</span></div>';
}

How to display only title field name in xl file using php

Here i want to do read the xl file in php,here i displayed all datas that means in xl file i have four columns called Title,Url,Visitors,Accesses.but for me don't want like this , i want only title name how can do this ? View my answer
<?php
include 'excel_reader.php'; // include the class
// creates an object instance of the class, and read the excel file data
$excel = new PhpExcelReader;
$excel->read('test.xls');
function sheetData($sheet) {
$re = '<table>'; // starts html table
$row = 1;
while($row <= $sheet['numRows']) {
$re .= "<tr>\n";
$column = 1;
$cell = isset($sheet['cells'][$row][1]) ? $sheet['cells'][$row][1] : '';
$re .= " <td>$cell</td>\n";
$re .= "</tr>\n";
$row++;
}
return $re .'</table>';// ends and returns the html table
}
$nr_sheets = count($excel->sheets);// gets the number of sheets
$excel_data = ''; // to store the the html tables with data of each sheet
// traverses the number of sheets and sets html table with each sheet data in $excel_data
for($i=0; $i<$nr_sheets; $i++) {
//$excel_data .= '<h4>Sheet '. ($i + 1) .' (<em>'. $excel->boundsheets[$i]['name'] .'</em>)</h4>'. sheetData($excel->sheets[$i]) .'<br/>';
$excel_data .= sheetData($excel->sheets[$i]) .'<br/>';
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example PHP Excel Reader</title>
<style type="text/css">
table {
border-collapse: collapse;
}
td {
border: 1px solid black;
padding: 0 0.5em;
}
</style>
</head>
<body>
<?php
// displays tables with excel file data
echo $excel_data;
?>
</body>
</html>
By observing the $sheet array you will get Title at the position of 4,1 as follows.
By changing this line as shown
$cell = isset($sheet['cells'][4][1]) ? $sheet['cells'][4][1] : '';
But it looks like you have copied this code from somewhere. It is hard to identify your need and modify it. Change the code as per your requirement and if any error occurs then post your question on SO
as per your requirement your sheetData function should be like this
function sheetData($sheet) {
$re = '<table>'; // starts html table
$x = 1;
while($x <= $sheet['numRows']) {
$re .= "<tr>\n";
$cell = isset($sheet['cells'][$x][1]) ? $sheet['cells'][$x][1] : '';
if($cell != 'Title'){ // check for title here
$re .= " <td>$cell</td>\n";
$re .= "</tr>\n";
}
$x++;
}
return $re .'</table>'; // ends and returns the html table
}

PHP script printing div

Is there a possible way to multiply code and print it out using PHP?
I am trying to make a script that checks users and draws a line depending on count.
CSS Code
#outer { // gray backround - always on.
background-color: #401800;
width: 150px;
height: 6px;
}
.inner { // used if there's less than 100 ppl online
width: 1px;
height: 6px;
display:block;
float:left;
}
.bigger { // used if 100+ people are online
width: 10px;
height: 6px;
display:block;
float:left;
}
}
.bigger.trys { // color for small px
background-color: green;
}
.inner.vienas { //color for big px
background-color: green;
}
PHP code ($rows = counted users):
if {$rows <= "0"
echo"<span class="inner vienas"></span>"; //draws small 1px width bar
}
elseif{$rows >= "10"
echo"<span class="inner vienas"></span><span class="inner vienas"> </span>"; // count =10 or greater - draws x2 bars.
}
elseif{$rows >= "100" // if users are 100 OR more counts new variable
$padala = $rows/10 //variable is users/10
echo 10*"<span class="bigger trys"></span>") //i want to print this out as 1px each 10 users
}
else {
echo "Script error";
}
Is there a way to do that?
Basicly you have lot of syntax error.
First, if statement need a condition:
Wrong:
if {
$rows <= "0"
echo"<span class="inner vienas"></span>"; //draws small 1px width bar
}
Correct (i don't know if $row have an integer or string, but if you use numbers, the correct is to storage an integer):
if ($rows <= 0) {
echo '<span class="inner vienas"></span>';
}
Second, echo:
You have an error with double quote marks when inserting HTML code, you don't have to cut the echo
Wrong:
echo"<span class="inner vienas"></span>";
Correct (using simple quotes):
echo '<span class="inner vienas"></span>';
Another error is that echo*10, you need to use a for loop.
for($i=0; $i<=9; $i++) {
echo '<span class="bigger trys"></span>';
}
Btw, I don't understand what you want, but the correct maybe is this:
if ($rows <= 0) {
echo '<span class="inner vienas"></span>';
} else if ($rows >= 10) {
echo '<span class="inner vienas"></span><span class="inner vienas"> </span>';
} else if ($rows >= 100) {
$padala = $rows / 10
for($i=0; $i<=9; $i++) {
echo '<span class="bigger trys"></span>';
}
} else {
echo "Script error";
}
Here you can read more about if statements and for:
PHP Manual - If Statements
PHP W3Schools - For loops
Without knowing more about your data, I'm not sure how I would go about doing what you want to accomplish. However, Here is your above code with the syntax fixes.
The conditions in the if statements should be wrapped in Parentheses, and the double quotes in the strings after the the echo functions should be escaped
if ($rows <= "0") {
echo"<span class=\"inner vienas\"></span>"; //draws small 1px width bar
} elseif($rows >= "10") {
echo"<span class=\"inner vienas\"></span><span class=\"inner vienas\"> </span>"; // count =10 or greater - draws x2 bars.
} elseif($rows >= "100") { // if users are 100 OR more counts new variable
$padala = $rows/10 //variable is users/10
echo 10*"<span class=\"bigger trys\"></span>") //i want to print this out as 1px each 10 users
} else {
echo "Script error";
}

PHP to ouput html code for text gradient or "rainbow text" of sorts

Let me start by saying I have scoured the internet all day looking for a solution, and I'm just stumped. I managed to find enough code snippets to put together an "almost" working version of what I need -- but to be completely honest I'm just lost when it comes to how to make it work.
Here's what I'm trying to do:
I'm trying to make a php function that will take 2 or maybe 3 colors, and apply them as a smooth gradient to a text string. I need the function to output the actual HTML code for the gradient. How I envision it working is: it will take the message string and split it into the individual characters, and then color each character in such a way that when it's displayed with the html output, it will look like a smooth fade from one color to the next. Right now I'm testing the function with 2 colors that I've just defined inside it, (FF0000 and 0000FF). I can't seem to get it to color the entire string. It seems to grab the first letter, and do part of the transition, and then just stop.
Here's a screenshot of what I'm trying to make it look like:
Here's a screenshot of what mine comes out looking like (including the html output for explanation sake)
Here's the code that I'm using:
<?php
function html2rgb($color)
{
if ($color[0] == '#')
$color = substr($color, 1);
if (strlen($color) == 6)
list($r, $g, $b) = array($color[0].$color[1],
$color[2].$color[3],
$color[4].$color[5]);
elseif (strlen($color) == 3)
list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
else
return false;
$r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
return array($r, $g, $b);
}
function rgb2html($r, $g=-1, $b=-1)
{
if (is_array($r) && sizeof($r) == 3)
list($r, $g, $b) = $r;
$r = intval($r); $g = intval($g);
$b = intval($b);
$r = dechex($r<0?0:($r>255?255:$r));
$g = dechex($g<0?0:($g>255?255:$g));
$b = dechex($b<0?0:($b>255?255:$b));
$color = (strlen($r) < 2?'0':'').$r;
$color .= (strlen($g) < 2?'0':'').$g;
$color .= (strlen($b) < 2?'0':'').$b;
return '#'.$color;
}
echo "<h1>Result:</h1>";
$src_color = html2rgb('FF0000');
$dst_color = html2rgb('0000FF');
print_r($dst_color);
for($i=0; $i<3; $i++)
$step_color[$i] = ( $dst_color[$i] - $src_color[$i] ) / 30.30;
// step_color array contains difference between adjacent color stripes
$html_out = ''; // html code container
for($j=0; $j<60; $j++)
{
// generate color stripe code
$message = 'I am trying to make this text string fade from one color to another';
$counter = strlen($message);
$array = str_split($message);
$mycount = 0;
if($mycount < $counter){
$line = '<b><font color=" '.rgb2html($src_color).';">'.$array[$mycount].'</font></b>';
$html_out .= "{$line}"; // save color stripe to display HTML code later
$mycount = $mycount + 1;
}
echo $line; // output color stripe to browser
for($i=0; $i<1; $i++) // incrementing each color component
$src_color[$i] += $step_color[$i];
}
?>
<h1>HTML Code:</h1>
<pre><?php
// output HTML code replacing < and > with < and >
$stuff = strtr($html_out, array('&' => '&',
'<' => '<',
'>'=> '>'));
echo $stuff;
I'm fairly new to this sort of thing, so please don't be too brutal on me if my code is "arse-backwards" or poor. Can anyone point me in the right direction? I'm just at a loss for how to get it to do what I want it to do.
Thank you very much for taking the time to read this, and for any advice you can offer!
Edit: image link for bottom screenshot to make it easier to see
http://i.stack.imgur.com/vsfdQ.jpg
UPDATE -- Ok, I've re-written most of the function and I almost have it working. The issue that I'm having now is that it's repeating the entire string over and over. It is applying the fade, but not the way it's supposed to. I need it to fade from one color to the next across the string. Here is a new screenshot of what it's doing now:
Here's the link for that so you can see it easier:
http://i.stack.imgur.com/X0Pmq.jpg
Here's the new code that I'm using:
<?php
function rgb($rgb) {
$ret = '';
foreach ($rgb as $x) {
// Make sure the RGB values are 0-255...
$x = max(0, min(255, $x));
// create a 2 digit hex value for this color component...
$ret .= ($x < 16 ? '0'.dechex($x) : dechex($x));
}
return '#'.$ret;
}
// Returns a fade of $from into $to by $amount ($from and $to are RGB arrays)...
function fade($from, $to, $amount) {
$rgb = array();
// Go through the RGB values and adjust the values by $amount...
for ($i = 0; $i <= 2; $i++) {
$rgb[$i] = (($to[$i] - $from[$i]) * $amount) + $from[$i];
}
return $rgb;
}
$string = 'testing out the fade function here';
//$string1 = strlen($string);
for ($j = 0; $j < 1; $j += .01) {
$color = rgb(fade(array(255,0,0), array(0,255,0), $j));
for($i=0;$i<strlen($string);$i++){
echo "<font style='color:$color'>$string[$i]</font>";
}
}
Is anyone able to tell me how to make it print the string just ONCE, with the fade properly applied to the string?
Thank you all so much for all of your time and expertise!
Check second example as it is more of what you're looking for.
Just use php to add the html elements and their ids or classes and then use css to give the gradient.
Example:
#id_of_element { /*or class of element*/
background: -webkit-linear-gradient(left, red , blue);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
/* the following would cover other browsers...not sure about IE */
background: -webkit-linear-gradient(left, red , blue); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, red, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, red, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, red , blue); /* Standard syntax */
/* then just add the -o- or -moz- etc. */
}
Depending on which angle or direction you want to gradient to go -> just use php (and/or javascript) to alter the value of the background: -webkit-linear-gradient(direction, color1 , color2);
THE FOLLOWING IS THE CODE EXAMPLE
Try the code below as an example:
Afterwards, open the page up in a web browser. It should have text that goes from black to white.
After APPEND this to the url:
?color1=FFFFFF&color2=000000
So the full url should look something like this:
http://yoursite.com/pageName.php?color1=FFFFFF&color2=000000
Now the gradient is reversed. because color1 originally started out as #000000 but the php switched it because of the value it had from the GET request.
Here is the code example:
<?php
$textOutput = '';
?>
<?php if(isset($_GET['color1']) && isset($_GET['color2'])):
$textOutput = '';
$userFirstInput = $_GET['color1']; // these are the posts or gets you send from your form
$userSecondInput = $_GET['color2']; // these are the posts or gets you send from your form
$firstColor = $userFirstInput; // #FFFFFF for example
$secondColor = $userSecondInput; // #000000 for example
$textOutput .= '.spans{';
$textOutput .= 'background: -webkit-linear-gradient(left, #'. $firstColor . ', #'.$secondColor .');';
$textOutput .= '-webkit-background-clip: text;';
$textOutput .= '-webkit-text-fill-color: transparent;';
?>
<?php else:
$textOutput = '';
$textOutput .= '.spans{';
$textOutput .= 'background: -webkit-linear-gradient(left, #000000 , #FFFFFF);';
$textOutput .= '-webkit-background-clip: text;';
$textOutput .= '-webkit-text-fill-color: transparent;';
?>
<?php endif ?>
<!DOCTYPE html>
<html>
<head>
<style>
<?php echo $textOutput; ?>
</style>
<span class="spans">IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII</span>
</body>
</html>
If you need help getting the user input, that I can help with as well. I use ajax to send a post or get up to PHP and check/sanitize the inputs.
Why don't do like that
$string = 'My text'
$count = 0;
for($i=0,$i<=255,$i++){
for($i_i=0,$i_i<=255,$i_i++){
for($i_i_i=0,$i_i_i<=255,$i_i_i++){
echo '<span style="color:rgb('.$i.','.$i_i.','.$i_i_i.')">'.$string[$count].'</span>';
if($count == strlen($string))break;
$count++;
}
if($count == strlen($string))break;
}
if($count == strlen($string))break;
}
Or set some other values of $i... to get another colors.

Cannot change src of image with Javascript in some versions of Chrome

Never could have imagined that chrome would have been the browser giving me grief, but the slideshow for our new website does not function properly in some versions of Chrome.
The error occurs here:
"mainPicture.src = \''.$directory.$current_pic.'\'; setMarkerPos('.$i.')"
Claiming that I can't modify mainPicture, an id that doesn't exist.
Obviously, other browsers don't have a problem seeing this object.
All help is much appreciated!
.
You can find the page here.
Source code:
<?php
/********************************************************************
* GATHER IMAGES FROM IMAGE DIRECTORY *
********************************************************************/
// Define directory where images are stored
$directory = "../../images/slideshow/";
// Create blank array to store image names
$pic_array = array("");
$num_pics;
// Create number to define position of images in array
$counter = 0;
// Gather pictures from image directory
if(is_dir($directory))
{
// Open directory to view files
if($dh = opendir($directory))
{
// Continue while still files to view
while(($file = readdir($dh)) !== false)
{
// Stop if picture limit of 6 reached
if($counter == 6)
break;
// Gather if object found is file or directory
$file_check = filetype($directory.$file);
// If object is a file, add it to the slideshow
if ($file_check == "file")
{
$extension = substr($file, strpos($file, "."));
if ($extension == ".png" || $extension == ".jpg")
{
$pic_array[$counter] = $file;
$counter++;
}
}
}
}
}
// Determine number of pics gathered
$num_pics = count($pic_array);
?>
<html>
<head>
<link href="scripts/slideshow.css" rel="stylesheet" type="text/css">
<?php
/********************************************************************
* CONTROL BEHAVIORS OF SLIDESHOW *
********************************************************************/
?>
<!-- Begin script to control slideshow -->
<script type = "text/javascript">
var thumbTop = 450; // starting value of thumb.style.top (make sure multiple of increment)
var highestTop = 342; // highest point mask can be on screen ,-, (make sure multiple of increment)
var lowestTop = 450; // lowest point mask can be on screen ,_, (make sure multiple of increment)
var delay = 2; // speed in which slide up and down methods are called
var increment = 5; // value that thumbTop increments with each method call
var intervalUp; // interval for thumb upward movements
var intervalDown; // interval for thumb downward movements
function startThumbSlideUp()
{
window.clearInterval(intervalDown);
intervalUp = window.setInterval(thumbSlideUp,delay);
}
function startThumbSlideDown()
{
window.clearInterval(intervalUp);
intervalDown = window.setInterval(thumbSlideDown,delay);
}
function thumbSlideUp()
{
thumbTop -= increment;
if (thumbTop <= highestTop)
{
thumbTop = highestTop;
window.clearInterval(intervalUp);
}
else
thumbMask.style.top = thumbTop;
}
function thumbSlideDown()
{
// Added to fix issue where images would start from too large a height
if (thumbTop <= highestTop)
thumbTop = highestTop;
thumbTop += increment;
if (thumbTop >= lowestTop)
{
thumbTop = lowestTop;
window.clearInterval(intervalDown);
}
else
thumbMask.style.top = thumbTop;
}
// Move marker above image <pos>
function setMarkerPos(pos)
{
marker.style.left = 600 - (66 * (pos)) + 19;
}
</script>
</head>
<?php
/********************************************************************
* DISPLAY SLIDESHOW *
********************************************************************/
// Start body and make images unhighlightable
echo '<body onselectstart="return false" style="margin: 0px;">';
// Create base value to increment horizontal position of thumbnails
$curr_thumb_left = 595; // (ignore this comment) 660<width of image> - 66<width of thumb> - 10<space between side> // 660
// Create and display main (large) image and image thumbnails
echo '<div id="mask" onmouseout = "startThumbSlideDown()" onmouseover = "startThumbSlideUp();">
';
echo '<img src = "'.$directory.$pic_array[0].'" id = "mainPicture" height = "420" width = "660" style = "z-index: -1; position:absolute;"/>
';
echo '<div id="thumbMask" height="66" width="660" style="z-index: 1; top: 450px; position: absolute;">
';
echo '<img id="marker" src="images/marker.png" height="10" width="10" style="z-index: 2; top: 0px; position: absolute;" onload="setMarkerPos(0);"/>';
// Search through image array, then assign names to and display thumbnails
for ($i=0; $i < $num_pics; $i++)
{
// Point to pic in array
$current_pic = $pic_array[$i];
// Create and display image thumbnails
if ($current_pic !== "")
{
echo '<img src = "'.$directory.$current_pic.'" id = "thumb'.$i.'" height = "50" width = "50" style = "left:'.$curr_thumb_left.'px; top: 10px; border: 3px white solid; position: absolute;" onclick = "mainPicture.src = \''.$directory.$current_pic.'\'; setMarkerPos('.$i.')"/>
';
// Move left value to the left [50px width + (3px padding * 2 sides) + 10px space between = 66px]
$curr_thumb_left -= 66;
}
}
echo '</div>';
echo '</div>';
?>
</body>
</html>
Chrome doesn't make image elements available by just their "id" value; you have to use document.getElementById("mainPicture") to get a reference to the DOM element. That'll work in all browsers anyway, so it's safe to just code it that way.
You are attempting to alter the src of mainPicture as though it were a global variable:
mainPicture.src = '.....';
Try referencing mainPicture by its id instead:
document.getElementById('mainPicture').src = '......';
You're not actually setting what mainPicture is, other browsers must be guessing whereas Chrome is doing what it should. Change:
echo '<img src = "'.$directory.$current_pic.'" id = "thumb'.$i.'" height = "50" width = "50" style = "left:'.$curr_thumb_left.'px; top: 10px; border: 3px white solid; position: absolute;" onclick = "mainPicture.src = \''.$directory.$current_pic.'\'; setMarkerPos('.$i.')"/>
to
echo '<img src = "'.$directory.$current_pic.'" id = "thumb'.$i.'" height = "50" width = "50" style = "left:'.$curr_thumb_left.'px; top: 10px; border: 3px white solid; position: absolute;" onclick = "document.getElementById('mainPicture').src = \''.$directory.$current_pic.'\'; setMarkerPos('.$i.')"/>

Categories