CSV new Line Character - php

I have an Excel Template that i use to fill in data and export that to CSV to populate the following page on my website.
http://play.mink7.com/ifocus_v4/careers.php
When i export the file in Windows i get the formatting for the new line charcter right. But when i export the same excel file from MAC i dont get the new line character.
Windows File
play.mink7.com/ifocus/win.csv
and
MAc File
play.mink7.com/ifocus/mac.csv
.
My Code
<?php
include_once("libs/csv2json/CSVParser.php");
$jsonParser = CSVParserFactory::Create("json");
$path = "uploads/jobs.csv";
//This property will use the first row to convert the results into a
//json object array
$jsonParser->IsFirstRowHeader = true;
$jobs = $jsonParser->Parse($path);
$jobs = json_decode($jobs, true);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>iFocus - Careers</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,400,700,300' rel='stylesheet' type='text/css'>
<script src="js/modernizr.custom.34639.js"></script>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.accordion.min.js"></script>
<link rel="stylesheet" href="css/normalize.min.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div id="header" class="wrapper">
<header class="container">
<div id="logo"><img src="img/logo.png" width="185" height="69" alt="ifocus logo"></div>
<nav id="primaryNav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Case Studies</li>
<li>Services</li>
<li>Testimonials</li>
<li><a class="active" href="careers.php">Careers</a></li>
<li>Contact Us</li>
</ul>
</nav>
<div class="clearfix"></div>
</header>
</div>
<div id="mainBody">
<div class="container">
<h3>Careers</h3>
<h4>iFocus is looking for experienced professionals in the following areas: </h4>
<p>Email your resume to jobs#ifocussystec.com</p>
<div class="active-jobs">
<?php $i = 1; ?>
<?php foreach($jobs as $j): ?>
<h3 class="accordion" id="nav-section<?php echo $i++; ?>"><?php echo $j['job_code']." - ".$j['title']; ?><span></span> </h3>
<div class="accordion-content">
<p><strong>Relevant Experience:</strong> <?php echo $j['experience']; ?></p>
<p><strong>Job Description::</strong></p>
<?php $job_desc = explode("\n", $j['job_desc']);?>
<ul>
<?php foreach($job_desc as $jd):?>
<li><?php echo $jd; ?></li>
<?php endforeach; ?>
</ul>
<p><strong>Skill Set:</strong></p>
<?php $skillsets = explode("\n", $j['skillsets']);?>
<ul>
<?php foreach($skillsets as $s):?>
<li><?php echo $s; ?></li>
<?php endforeach; ?>
</ul>
<p><strong>Key Words:</strong> <?php echo $j['keywords']; ?></p>
</div>
<?php endforeach; ?>
</div>
<div class="clearfix"></div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.accordion').accordion({
defaultOpen: 'nav-section1',
cookieName: 'accordion_nav'
});
});
</script>
</body>
</html>
Lib Link: https://github.com/crosbymichael/php-csv-to-xml-json
i have tried using "\r\n" but it doesnt give the formating either

PHPs file functions do not reliably recognize line endings from Macs (if they use \r character, as Mac Excel does, if I recall correctly.)
You need to set auto_detect_line_endings in php.ini to true, then it will properly recognize line endings, whether they are \n, \r, or \r\n.
This setting is PHP_INI_ALL, which means that it can be set anywhere, i.e., in php.ini, in .htaccess for a particular directory, or even with ini_set, e.g., ini_set('auto_detect_line_endings', true)

Related

PHP echoing in wrong location of html

I'm attempting to make a template based system to deliver content but I've run into a problem that I just can't seem to solve. When I try to echo out variables that have data from includes it gets outputted in the wrong section of my html.
Below is 'newstuff.php' which is my page to be executed on the browser, the offending variables are $php $head $content.
<?php
$php = include "templates/content/newstuff/phpCode.php";
$head = include "templates/content/newstuff/head.html";
$content = include "templates/content/newstuff/content.php";
include realpath(dirname(__FILE__)).'/templates/templateMain.php';
?>
Below is 'tempalteMain.php' this is my tempalte. Note the location of the echoing of $php $head $content.
<?php
echo $php;
?>
<!DOCTYPE html>
<html>
<head>
<?php echo $head; ?>
</head>
<body class="body1" onload="inputBlur2()">
<div class="borderLine"></div>
<div class="banner"></div>
<div class="mainContent1" >
<div class="header1" >
<div class="headerContainer" >
<ul class="navList1">
<li><a id = "B0" href="index.php">New Stuff</a></li>
<li><a id = "B1" href="MainPage.php">Products</a></li>
<li><a id = "B2" href="ProjectsPage.php">Projects</a></li>
<li><a id = "B3" href="AOrdering.php">About Ordering</a></li>
<li><a id = "B4" href="ContactMe.php">Contact Us</a></li>
<li><a id = "B5" href="FAQPage.php">FAQ</a></li>
<li><a id = "B6" href="SCart.php">My Cart</a></li>
</ul>
</div>
</div>
<div class="content1">
<?php echo $content; ?>
</div>
</div>
</body>
</html>
Below is 'head.html' this provides the code to be delivered by the $head PHP variable.
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/../StylePR.css">
<title>KickUp Electronics</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
Below is 'content.php' this provides the code to be delivered by the $content PHP variable.
<p>Welcome to the new stuff page!!!</p>
Finally, this is the page source that gets outputted taken from the chrome DOM editor. Note the locations of the information from content.php are wrong and there are strange '1's that are echoed out (also, when viewing the page source, the information from head.html is placed outside the html tags).
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/../StylePR.css">
<title>KickUp Electronics</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>
<body class="body1" onload="inputBlur2()">
<p>Welcome to the new stuff page!!!</p> <!--Wrong Location!-->
1
1
<div class="borderLine"></div>
<div class="banner"></div>
<div class="mainContent1">
<div class="header1">
<div class="headerContainer">
<ul class="navList1">
<li><a id="B0" href="index.php">New Stuff</a></li>
<li><a id="B1" href="MainPage.php">Products</a></li>
<li><a id="B2" href="ProjectsPage.php">Projects</a></li>
<li><a id="B3" href="AOrdering.php">About Ordering</a></li>
<li><a id="B4" href="ContactMe.php">Contact Us</a></li>
<li><a id="B5" href="FAQPage.php">FAQ</a></li>
<li><a id="B6" href="SCart.php">My Cart</a></li>
</ul>
</div>
</div>
<div class="content1">
1 </div>
</div>
</body></html>
I tried searching many times for a solution to no avail. Is this a problem with the echo being executed before the html fully loads? Any help would be highly appreciated!
You're using includes wrong.
$php = include "templates/content/newstuff/phpCode.php";
is immediately outputting the output of that file, and setting $php to 1 (i.e. "it worked!").
Handling Returns: include returns FALSE on failure and raises a warning. Successful includes, unless overridden by the included file, return 1. - http://php.net/manual/en/function.include.php
You can use output buffering to capture the output, but a better solution is probably moving the include calls directly into templateMain.php.

PHP: How to load a web page with a specific include?

I'm working on a project where I have audio, video and picture files in different directories and want to write a simple web interface for those. I got everything working pretty good so far, pictures are displayed by lightbox, audio and video are played by jPlayer.
I have a directory stucture like this
ARCHIVE/
_RES/
CSS/
JPLAYER/
LIGHTBOX/
index.php #this is the start page with links to the other index.php files
VIDEO/
PICTURES/
ALBUM1/
IMG/
T_IMG/
index.php
ALBUM2/
IMG
T_IMG/
index.php
ALBUMn/
IMG/
T_IMG/
index.php
AUDIO
ALBUM1
index.php
OGG/
SONG#1.ogg
SONG#n.ogg
SONG FUN. ogg
MP3/
SONG#1.mp3
SONG#n.mp3
SONG FUN.mp3
My Problem now is, when I want to change something, for example, in the audio player, I have to edit every index.php in every ALBUMx/ directory inside AUDIO.
I'm sure there is a much simpler way: instead of have many index.php files, just having one index.php file, and when I click on link, AUDIO -> ALBUM1 it automatically loads a .html document that shows the audio player and fills the playlist with the audio files from the Album I choose.
This is example code for my AUDIO ALBUM index.php.
The ones for Pictures and Video look similar, except for having different player option e.g. for video or, in case of pictures, in has a lightbox implemented.
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<link href="/archive/_res/style.css" rel="stylesheet" />
<?php
$parent = dirname(dirname($_SERVER['SCRIPT_NAME'])) . '/';
$dirname = basename(__DIR__);
echo '<title>'.$parent.$dirname.' </title>';
?>
<link href='http://fonts.googleapis.com/css?family=Raleway:100,400' rel='stylesheet' type='text/css'>
<!-- JPLAYER AUDIO VIDEO -->
<!--link type="text/css" href="../../_res/jplayer/skin/pink.flag/jplayer.pink.flag.css" rel="stylesheet" /-->
<link type="text/css" href="../../_res/jplayer/skin/blue.monday/jplayer.blue.monday.css" rel="stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="../../_res/jplayer/jquery.jplayer.min.js"></script>
<script type="text/javascript" src="../../_res/jplayer/jplayer.playlist.min.js"></script>
<?php
$mp3folder = 'mp3/';
$oggfolder = 'ogg/';
$filetype = '*.*';
$mp3files = glob($mp3folder.'*.mp3');
$oggfiles = glob($oggfolder.'*.ogg');
echo '
<script type="text/javascript">
$(document).ready(function(){
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [';
for ($i=0; $i<count($mp3files); $i++) {
$namerr[$i] = substr($oggfiles[$i],strlen($oggfolder),strpos($oggfiles[$i], '.')-strlen($oggfolder));
echo '{'."\n";
echo 'title:"'.$namerr[$i].'",'."\n";
echo 'mp3:"'.dirname($mp3files[$i]).'/'.rawurlencode(basename($mp3files[$i])).'",'."\n";
echo 'ogg:"'.dirname($oggfiles[$i]).'/'.rawurlencode(basename($oggfiles[$i])).'",'."\n";
echo 'free: "true"'.','."\n";
echo 'poster:"'.$mp3folder.'cover.png",'."\n";
echo '},'."\n";
}
echo '
], {
swfPath: "../../_res/jplayer",
supplied: "ogg, mp3",
wmode: "window",
size: {
width: "300px",
height: "300px",
cssClass: "jp-video-240p"
},
smoothPlayBar: true,
keyEnabled: true
});
});
</script>';
?>
<!-- JPLAYER AUDIO VIDEO //-->
<script>
function bottop (div_id) {
$('#'+div_id).animate({top:"-=140"},500, 'swing');
}
function topbot (div_id) {
$('#'+div_id).animate({top:"+=140"},500, 'swing');
}
function fade_in (div_id) {
$('#'+div_id).fadeIn(0);
}
function fade_out (div_id) {
$('#'+div_id).fadeOut(0);
}
</script>
</head>
<body>
<div id="shownav" class="shnav">
<span class="thinl4 db" onclick="topbot('topper');fade_out('shownav');">Show Navigation bar!</span>
</div>
<div id="topper">
<div id="hidenav" class="shnav">
<span class="thinl4 db" onclick="bottop('topper');fade_in('shownav');">Hide Navigation bar!</span>
</div>
<div id="backtoarchive" class="fl thinl">
<table id="keks">
<tr>
<td class="bif"><</td>
<td id="bli">Back to Archive</td>
</tr>
</table>
</div>
<?php include '/var/www/webaccount/html/archive/_res/nav.php'; ?>
<?php
$parent = dirname(dirname($_SERVER['SCRIPT_NAME'])) . '/';
$dirname = basename(__DIR__);
echo '<div id="where" class="fl">';
echo 'You are here: <em>'.$parent.$dirname.'</em>';
echo '</div>';
?>
</div>
<div id="jplayer-wrap">
<div id="jp_container_1" class="jp-video jp-video-270p">
<div class="jp-type-playlist">
<div id="jquery_jplayer_1" class="jp-jplayer"></div>
<div class="jp-gui">
<div class="jp-video-play">
play
</div>
<div class="jp-interface">
<div class="jp-progress">
<div class="jp-seek-bar">
<div class="jp-play-bar"></div>
</div>
</div>
<div class="jp-current-time"></div>
<div class="jp-duration"></div>
<!-- added style below to fix floating issue (default was clear:both by css) -- not important to code function -->
<div class="jp-controls-holder" style="clear:left;">
<ul class="jp-controls">
<li>previous</li>
<li>play</li>
<li>pause</li>
<li>next</li>
<li>stop</li>
<li>mute</li>
<li>unmute</li>
<li>max volume</li>
</ul>
<div class="jp-volume-bar">
<div class="jp-volume-bar-value"></div>
</div>
<ul class="jp-toggles">
<li>full screen</li>
<li>restore screen</li>
<li>shuffle</li>
<li>shuffle off</li>
<li>repeat</li>
<li>repeat off</li>
</ul>
</div>
<div class="jp-title">
<ul>
<li></li>
</ul>
</div>
</div>
</div>
<div class="jp-playlist">
<ul>
<!-- The method Playlist.displayPlaylist() uses this unordered list -->
<li></li>
</ul>
</div>
<div class="jp-no-solution">
<span>Update Required</span>
To play the media you will need to either update your browser to a recent version or update your Flash plugin.
</div>
</div>
</div>
</div>
</body>
</html>
I guess I would have to make single "modules" that contain the jplayer/lightbox stuff and <?php include .. ?> those and have it load the correct files.
So when I click on a link for AUDIO -> ALBUM1 the html/php link should load something like
index.php?load=audio,files=audio/album1
If someone has a hint for me, it would be so great!!!
This is my first PHP Project and I'm keen to learn!
Thank you,
vincent.

Php different images in every page

I am designing my own site. First I created a template with header.php and footer.php I put them in the includes folder. So, everytime I am going to make a new page like "about page" all I have to do is to call them using the code below:
<body>
<?php include("includes/header.php"); ?>
<?php include("includes/footer.php"); ?>
</body>
</html>
Here is the code in my header.php
<div id="headwrapper">
<header>
<div id="logo"><img src="images/adlogo.png"/></div>
<div id="homefeature">622x82</div>
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>portfolio</li>
<li>Blogs</li>
<li>Contact</li>
</ul>
</div>
</header>
</div><!--end of headwrapper-->
But my index.php and my about page have the same header image. Is there a way or code that can accomplish the work for different header images for every page? Example on index.php I want to have image1 and to my about page I want to have image2. That's all thank you by the way I am not using a wordpress my site is not a wordpress.
Another solution.
In header.php you call function $_SERVER['PHP_SELF'] for get page name and then selected image for that page. You could modify like this
<?php
$imageName = "";
if($_SERVER['PHP_SELF'] == "index.php")
{
$imageName = "images/1.png";
}
elseif($_SERVER['PHP_SELF'] == "aboutus.php")
{
$imageName = "images/2.png";
}
?>
<div id="headwrapper">
<header>
<div id="logo"><img src="'".<?=$imageName?>."'"/></div>
<div id="homefeature">622x82</div>
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>portfolio</li>
<li>Blogs</li>
<li>Contact</li>
</ul>
</div>
</header>
</div><!--end of headwrapper-->
Given your structure, I think you can set your header file like this:
<body>
<?php $header_image = "about_us_header.jpg"; ?>
<?php include("includes/header.php"); ?>
<?php include("includes/footer.php"); ?>
</body>
and reference the variable in your header:
<div id="headwrapper">
<header style="background: url(<?php echo $header_image; ?>);">
But wait I thought of a better way
you can do it in css like this:
<body class="aboutus">
<?php include("includes/header.php"); ?>
<?php include("includes/footer.php"); ?>
</body>
and in your css stylesheet:
body.aboutus header {
background: url(whatever.jpg);
}

How do I add a class of current to my navigational list items and links?

I've tried a few different ways to add a class of current on my navigation.
I read an article on doing so at: http://alistapart.com/article/keepingcurrent
So far I'm having no luck incorporating any of the ways into my site.
I feel like I'm missing something.
I pull my navigation into the site with an includes file called nav.php:
<div id="nav">
<div id="nav-container">
<ul id="nav-content" class="top menu">
<li<?php if ($thisPage=="home")
echo " id=\"currentpage\""; ?>>
Home</li>
<li<?php if ($thisPage=="portfolio")
echo " id=\"currentpage\""; ?>>
Portfolio</li>
<li<?php if ($thisPage=="services")
echo " id=\"currentpage\""; ?>>
Services</li>
<li<?php if ($thisPage=="resources")
echo " id=\"currentpage\""; ?>>
Resources</li>
<li<?php if ($thisPage=="blog")
echo " id=\"currentpage\""; ?>>
Blog</li>
<li<?php if ($thisPage=="contact")
echo " id=\"currentpage\""; ?>>
Contact</li>
</ul>
</div>
</div>
This is what I have in the body of the index page:
<?php $thisPage="home"; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Kristine Morical : Home</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="Kristine Morical" />
<?php include('http://www.kristinemorical.com/includes/head.php'); ?>
</head>
<body id="body">
<?php include('http://www.kristinemorical.com/includes/header.php'); ?>
<?php include('http://www.kristinemorical.com/includes/nav.php'); ?>
<div id="outer" class="clearfix">
<div id="sidebar-wrapper">
<?php //include('http://www.kristinemorical.com/includes/sidebar.php'); ?>
</div>
<div id="content" role="main">
</div> <!-- end #main -->
</div> <!-- end #outer -->
<?php include('http://www.kristinemorical.com/includes/footer.php'); ?>
</body>
</html>
I'm not sure what I'm doing wrong.
First, you can use the ternary condition for cleaner code, and second, use a css class for easier styling (which would allow multiple, if you add other navigation elements):
<li<?= ($thisPage=="services" ? ' class="currentPage"' : '') ?>>
Services
</li>
It can get tedious too to always set $thisPage, so you could go step further and have PHP try to figure it out based on the current request uri.
If you have problems where the class is never printing when it should, then do a var_dump or something on $thisPage to make sure it's being set properly.
Try this:
<div id="nav">
<div id="nav-container">
<ul id="nav-content" class="top menu">
<?php if ($thisPage=="home") echo "<li id=\"currentpage\">"; else echo "<li>";?>
Home</li>
<?php if ($thisPage=="portfolio") echo "<li id=\"currentpage\">"; else echo "<li>";?>
Portfolio</li>
<?php if ($thisPage=="services") echo "<li id=\"currentpage\">"; else echo "<li>";?>
Services</li>
<?php if ($thisPage=="resources") echo "<li id=\"currentpage\">"; else echo "<li>";?>
Resources</li>
<?php if ($thisPage=="blog") echo "<li id=\"currentpage\">"; else echo "<li>";?>
Blog</li>
<?php if ($thisPage=="contact") echo "<li id=\"currentpage\">"; else echo "<li>";?>
Contact</li>
</ul>
</div>
</div>
That will work if you're using ID tags but if you really want to use a class, then you should be using class tags instead. It depends on how you're declaring the class in your head tags of your webpage or in your css file. If you're declaring the class with the # sign then the above code will work but it's not the best practice. You would want to declare the class with a period sign instead and then use class tags in your webpage.

How can the screen be updated periodically for yahoo weather/simple pie?

I am using yahoo weather feed and simplepie to get weather for my digital display. Since it is a website run on a screen, I can't refresh the browser all the time manually.
I am just wondering is there anything eg jquery or php doc can help me update the weather information periodically as the weather changes?? If so would you be able to give me some directions on how to implement? your help is greatly appreciated.
Here is some of my code just in case it is useful
<div id="weather">
<div id="title">
<ul>
<!--<li> Outside Temp </li>-->
<li> Today </li>
<li> Tomorrow </li>
</ul>
</div> <!--title-->
<div id="forecast">
<div id="images">
<ul>
<?php foreach ($weather->get_forecasts() as $forecast): ?>
<li><img src="<?php echo $forecast->get_image(); ?>" alt="Weather" /></li>
<?php endforeach; ?>
</ul>
</div> <!--images-->
<div id="degrees">
<ul>
<?php foreach ($weather->get_forecasts() as $forecast): ?>
<li><?php echo $forecast->get_low(); ?>° <?php echo $forecast->get_high(); ?>° </li>
<?php endforeach; ?>
</ul>
</div><!--degrees-->
</div> <!--forecast-->
<!--</div> <!--second-->
Some header part info:
<php
require_once('simplepie/simplepie.inc');
require_once('simplepie/simplepie_yahoo_weather.inc');
$feed = new SimplePie();
$feed->set_feed_url('http://weather.yahooapis.com/forecastrss?w=1234567&u=c');
$feed->set_item_class('SimplePie_Item_YWeather');
$feed->init();
$weather = $feed->get_item(0);
?>
Thank you very much!
S:)
Since you're not already using JavaScript, a really simple way for you to periodically refresh the page might be to use the meta refresh tag. Although deprecated, it might be a quick way for you to get dynamic pages. Simply add the tag to the <head> of the page:
<meta http-equiv="refresh" content="5"> <!--Refresh the page every 5 seconds-->
However, you might want to consider using ajax to load your content into the page instead. This might not be the best possible approach to this but here's some quick and dirty code.
In the main page, you could use jQuery load to periodically hit the URL for your PHP script and load the content into a div for display:
<html>
<head>
<script type="text/javascript">
$(document).ready(function(){
setTimeout(loadWeather, 5000); //using setTimeout instead of a setInterval to avoid having multiple queries queue up when the first one fails to return within the timeout period
});
function loadWeather(){
$('#weather').load('weather.php);
setTimeout(loadWeather, 5000);
}
</script>
</head>
<body>
<div id="weather" />
</body>
</html>
where weather.php might look something like this:
<div id="weather">
<div id="title">
<ul>
<!--<li> Outside Temp </li>-->
<li> Today </li>
<li> Tomorrow </li>
</ul>
</div> <!--title-->
<div id="forecast">
<div id="images">
<ul>
<?php foreach ($weather->get_forecasts() as $forecast): ?>
<li><img src="<?php echo $forecast->get_image(); ?>" alt="Weather" /></li>
<?php endforeach; ?>
</ul>
</div> <!--images-->
<div id="degrees">
<ul>
<?php foreach ($weather->get_forecasts() as $forecast): ?>
<li><?php echo $forecast->get_low(); ?>° <?php echo $forecast->get_high(); ?>° </li>
<?php endforeach; ?>
</ul>
</div><!--degrees-->
</div> <!--forecast-->
<!--</div> <!--second-->

Categories