<?php
include("config.inc.php");
header("Cache-Control: no-cache, must-revalidate");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\"\"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head>";
echo "<title>$stitle</title>";
echo "<link rel=\"StyleSheet\" type=\"text/css\" href=\"theme/theme.css\" />";
echo "</head>";
?>
<head>
<META HTTP-EQUIV="Refresh" Content="10">
</head>
<?php
echo "<body>";
echo "<p align=\"center\">";
echo "Live Score:
---
";
$feed = "http://www.scorespro.com/rss/live-soccer.xml";
$fp = #fopen($feed,"r");
while(!feof($fp)) $raw .= #fgets($fp, 4096);
fclose($fp);
if( preg_match("/<item>(.*)<\/item>/", $raw, $rawitems ) ) {
$items = explode("<item>", $rawitems[0]);
$p = 5;
if ($npage == "")$npage = "1";
$countfile= count($items);
$countfile=$countfile-2;
$first=($npage*$p)-$p;
$npages = ceil($countfile / $p);
$items = array_reverse($items);
$next_arrays=($first+($p-1));
if($next_arrays>$countfile)$next_arrays=$countfile;
for ($i=($first); $i <= $next_arrays; $i++) {
preg_match("<title>(.*)</title>",$items[$i+1], $title );
preg_match("<link>(.*)</link>",$items[$i+1], $url );
preg_match("<description>(.*)</description>",$items[$i+1], $description);
$title[1] = str_replace("'", "", $title[1]);
$title[1] = str_replace("& ", "&", $title[1]);
echo $title[1].' ';
}
}
// if ($npage <= $npages and $npage>1) $gline_rew = '[url="'.$_SERVER["]Prev[/url] ';
// if ($npages > 1 and $npage<$npages) $gline_next = ' [url="'.$_SERVER["]Next[/url]';
// echo "
// ---
// Page {$npage} of {$npages}
// ".$gline_rew.$gline_next."
// ---
// ";
echo "</small>\n";
echo "</p>";
echo "</body>";
echo "</html>";
?>
<?php
public_static_function getInstance() {
static $instance;
$class = $title;
if ( ! $instance instanceof $class) {
$instance = new $class;
}
return $instance;
}
Hello!
I am making a live-score site using PHP.
But when I use this code and run it, I get a blank page.
I hope that I will find the mistake by myself but for now I can`t.
I would be happy if someone knows where the mistake is and help me.
Thank you in advance !!!
This is wrong
public_static_function getInstance() {
It should be
public static function getInstance() {
Also add error_reporting(E_ALL) when you have blank page(Which means you have errors)
Even when fixed, this will not work:
public static function getInstance() {
static $instance;
$class = $title;
...
}
Furthermore we have simpleXML_load_str() for handling RSS (or other XML) strings.
I think what you want is a decent way to handle an RSS feed.
Have a look at this post about RSS feeds
Good luck!
Related
I want to append sku in product title in Magento using php code. Can anyone please help me on that.
<?php
//set empty title
$title = '';
if ($_product = Mage::registry('current_product'))
{
$title = $_product->getName();
$pos = stripos($title);
$title = $this->getTitle();
}
?>
<title><?php echo $title; ?> | test</title>
Here is the working code for above question.
<?php
//set empty title
$title = '';
if ($_product = Mage::registry('current_product'))
{
$title = $_product->getName();
$sku = $_product->getSku();
$pos = stripos($title, $sku);
if($pos === false )
{
//no sku already - append now
$title.= ' - ' . $sku;
}
}
else
{
$title = $this->getTitle();
}
?>
<title><?php echo $title; ?> | test</title>
Hello i want to call a function using jquery. I tried a lot of ways and I can't get it.
This my principal webpage.
I'am uploading a file csv and pressing 'Crear' button, it uplaod the file while call the function.
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<SCRIPT type="text/javascript">
$(function (){
$('#btnxml').click(function (){
alert("aki");
$('#contenidos').load('csv.php');
});
});
</SCRIPT>
</head>
<body>
<form action="index.php" id="filecsv" method="post" enctype="multipart/form-data">
<input type="file" multiple="multiple" id="file" name="up_csv[]"/>
<input type="submit" value="Cargar" name="btnxml" id="btnxml" /><br />
</form>
<?php
global $archivocsv;
//tipos de archivos permitidos
$extensionxml = array('csv','txt');
//destino
$rutaupcsv = './csv/';
//multicargador de archivos
$vt=0;
for($i=0;$i<count($_FILES['up_csv']['size']);$i++){
for ($j=-1; $j<count($extensionxml); $j++) {
if (strripos($_FILES['up_csv']['name'][$i], $extensionxml[$j])!== false) {
$filename = 'lista';
$destino = $rutaupcsv.$_FILES['up_csv']['name'][$i];
$archivocsv = basename($_FILES['up_csv']['name'][$i]);
move_uploaded_file($_FILES['up_csv']['tmp_name'][$i],$destino);
$vt=$vt+1;
break;
}
$ns=1;
}
}
?>
<div id="contenidos"></div>
csv.php
<?php
echo '<html>';
echo '<head>';
echo '<meta content="text/html;charset=utf-8" http-equiv="Content-Type">';
echo '<meta content="utf-8" http-equiv="encoding">';
echo '</head>';
function makecsv() {
global $archivocsv;
$csv = './csv/' . $archivocsv;
$doc = new DOMDocument();
$row = 1;
$handle = fopen($csv, "r");
# Rows Counter
$csvxrow = file($csv);
$csvxrow[0] = chop($csvxrow[0]);
$anzdata = count($csvxrow);
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
#Load Predefined XML Template
$xml2 = $xml;
$xmlruta = './Templates/';
$xml = $xmlruta.$data[1].'.xml';
$doc->load($xml);
$xp = new DOMXPath($doc);
for ($c=0; $c < $num; $c++) {
foreach($xp->query('/ROOT/HEADER/#KEY[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[0];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#AUFNR[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[0];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#MATNR[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[1];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#GAMNG[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[2];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1AFFLL/E1FVOL/#MGVRG[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[2];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#GSTRS[. != ""]') as $attrib)
{
$attrib->nodeValue = $data[3];
}
foreach($xp->query('/ROOT/DATA/SAPMES/LOIPRO/E1FKOL/#GLTRS[. != ""]') as $attrib)
{
$fecha = new DateTime($data[3]);
$fecha->add(new DateInterval('P1M'));
$attrib->nodeValue = $fecha->format('Y-m-d');
}
}
$name = $data[0] .'-'. $data[1];
$doc->formatOutput = true;
echo $doc->saveXML();
$rutafinal = './XML/';
$doc->save($rutafinal.$name.'.xml');
}
fclose($handle);
echo $anzdata . " XML Creados" . "<br />";
return $data;
}
makecsv();
echo '</html>';
?>
I can't call the function.
it doesn't do anything when i try to call it.
EDIT: I think the problem is in my function. function edite
Javascript can´t play with php directly because JS is client side (only in browser) and PHP is server side (only in browser). What you can do is a PHP file that has the code you want to invoke, and make JS call that page.
Separate the CVS code from the form and make JS call the new php with the CVS php functionality.
jQuery runs in the client's browser whereas your PHP is running on your web server. If you wish to call a PHP function from your jQuery code, your best option is to do so using AJAX.
You can find documentation for implementing an AJAX call in jQuery here: https://api.jquery.com/jQuery.ajax/
You'll need to print the actual hmtl to do the function.
PHP
<?php
print '<script> makecsv() </script>';
?>
Here's my piece of code(full body code):
<body>
<script type='text/javascript'>
function AddEvent(Syear, Smonth, Sday, Eyear, Emonth, Eday, hallNumber){
...
}
</script>
<?php
function GetMonthByCoding($first , $second , $third) {
...
}
function GetDateByCoding($coding){
...
}
function GetDateFromLine($line){
...
}
$userid = '...';
$magicCookie = 'cookie';
$feedURL = "...";
$sxml = simplexml_load_file($feedURL);
foreach ($sxml->entry as $entry) {
$title = stripslashes($entry->title);
if ($title == "HALL") {
$summary = stripslashes($entry->summary);
$date = GetDateFromLine($summary);
echo ("<script type='text/javascript' language='JavaScript'> AddEvent(" . $date['start']['year'] . ", " . $date['start']['month'] . ", " . $date['start']['day'] . ", " . $date['end']['year'] . ", " . $date['end']['month'] . ", " . $date['end']['day'] . "); </script>");
}
}
?>
</body>
AddEvent() is JavaScript function defined earlier.
What I get in my browser is:
entry as $entry) { $title = stripslashes($entry->title); if ($title == "HALL") { $summary = stripslashes($entry->summary); $date = GetDateFromLine($summary); echo (""); } } ?>
Looks like it was an echo but as you can see there is no echo right in the middle of foreach.
Can anyone say what I am doing wrong?
PHP is not installed, or it is not enabled, or the file is not a .php file or the server has not been told to recognise it as a file to parse.
Try View Source and you should see all your PHP code. The only reason part of it shows up is because everything from <?php to the first > is considered by the browser to be an invalid tag.
I found the problem, it was in the name of variable sxml. I renamed it and the problem escaped.
Hi i am devloping sample site in php i need to translate whole website in to persian. how can it possible in php?? I have tried using the following code.. This code will working fine for deutsch conversion.
1. class.translation.php
<?php
class Translator {
private $language = 'en';
private $lang = array();
public function __construct($language){
$this->language = $language;
}
private function findString($str) {
if (array_key_exists($str, $this->lang[$this->language])) {
echo $this->lang[$this->language][$str];
return;
}
echo $str;
}
private function splitStrings($str) {
return explode('=',trim($str));
}
public function __($str) {
if (!array_key_exists($this->language, $this->lang)) {
if (file_exists($this->language.'.txt')) {
$strings = array_map(array($this,'splitStrings'),file($this->language.'.txt'));
foreach ($strings as $k => $v) {
$this->lang[$this->language][$v[0]] = $v[1];
}
return $this->findString($str);
}
else {
echo $str;
}
}
else {
return $this->findString($str);
}
}
}
?>
2.Register.php
<?php
require_once('class.translation.php');
if(isset($_GET['lang']))
$translate = new Translator($_GET['lang']);
else
$translate = new Translator('en');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php $translate->__('CSS Registration Form'); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15"/>
<link rel="stylesheet" type="text/css" href="css/default.css"/>
</head>
<body>
<form action="" class="register">
<h1><?php $translate->__('Registration'); ?><a class="flag_deutsch" title="deutsch" href="register1.php?lang=de"></a><a class="flag_english" title="english" href="register1.php"></a></h1>
<fieldset class="row1">
<legend><?php $translate->__('Account Details'); ?></legend>
<p>
<label><?php $translate->__('Email'); ?> *</label>
<input type="text"/>
<label><?php $translate->__('Repeat email'); ?> *</label>
<input type="text"/>
</p>
</fieldset>
<div><button class="button"><?php $translate->__('Register'); ?> »</button></div>
</form>
</body>
</html>
Is it possible to transilate to other laguages using this code?? I changed register1.php?lang=de to register1.php?lang=fa(persian).. But nothing hapens..anybody plese help
AS per me you can try this method.This method is already implemented in our system and it is working properly.
Make php file of each language and define all the variables and use those variables in pages.
for e.g
For english
english.php
$hello="Hello";
persian.php
$hello=html_entity_decode(htmlentities("سلام"));
Now use this variable to page like this.
your_page.php
<label><?php echo $hello; ?></label>
You have load specific language file as per get language variable from URL.
It is better that you have define this language variable into config file.
config.php
if(isset($_GET['lang']) && $_GET['lang']=='persian')
{
require_once('persian.php');
}
else
{
require_once('english.php');
}
If I were you, I'd do it like this:
/inc/lang/en.lang.php
define('_HELLO', 'Hello');
/inc/lang/fa.lang.php
define('_HELLO', 'سلام');
index.php
// $_SESSION['lang'] could be 'en', 'fa', etc.
require_once '/inc/lang/' . $_SESSION['lang'] . 'lang.php';
echo _HELLO;
Benchmark: Constants vs. Variables
Here you see why I offered using Constants not Variables:
const.php
echo memory_get_usage() . '<br>'; // output: 674,576
for ($i = 0; $i <= 10000; $i++) {
define($i, 'abc');
}
echo memory_get_usage() . '<br>'; // output: 994,784
var.php
echo memory_get_usage() . '<br>'; // output: 674,184
for ($i = 0; $i <= 10000; $i++) {
$$i = 'abc';
}
echo memory_get_usage() . '<br>'; // output: 2,485,176
original from #rbenmass :
try this:
function translate($q, $sl, $tl){
$res= file_get_contents("https://translate.googleapis.com/translate_a/single?client=gtx&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&sl=".$sl."&tl=".$tl."&hl=hl&q=".urlencode($q), $_SERVER['DOCUMENT_ROOT']."/transes.html");
$res=json_decode($res);
return $res[0][0][0];
}
//example--
echo translate("اسمي منتصر الصاوي", "ar", "en");
From an Perl trans script I extracted the following for 100% free php google translation this function:
See working demo on http://ogena.net
function translate($q, $sl, $tl){
if($s==$e || $s=='' || $e==''){
return $q;
}
else{
$res="";
$qqq=explode(".", $q);
if(count($qqq)<2){
#unlink($_SERVER['DOCUMENT_ROOT']."/transes.html");
copy("http://translate.googleapis.com/translate_a/single?client=gtx&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&sl=".$sl."&tl=".$tl."&hl=hl&q=".urlencode($q), $_SERVER['DOCUMENT_ROOT']."/transes.html");
if(file_exists($_SERVER['DOCUMENT_ROOT']."/transes.html")){
$dara=file_get_contents($_SERVER['DOCUMENT_ROOT']."/transes.html");
$f=explode("\"", $dara);
$res.= $f[1];
}
}
else{
for($i=0;$i<(count($qqq)-1);$i++){
if($qqq[$i]==' ' || $qqq[$i]==''){
}
else{
copy("http://translate.googleapis.com/translate_a/single?client=gtx&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&sl=".$s."&tl=".$e."&hl=hl&q=".urlencode($qqq[$i]), $_SERVER['DOCUMENT_ROOT']."/transes.html");
$dara=file_get_contents($_SERVER['DOCUMENT_ROOT']."/transes.html");
#unlink($_SERVER['DOCUMENT_ROOT']."/transes.html");
$f=explode("\"", $dara);
$res.= $f[1].". ";
}
}
}
return $res;
}
}
//sample usage
echo translate("Goede dag dames en heren", "nl", "en");
As i can read from the code, the translator class loads the translation data from en.txt file, if you want have 'fa' translation, just create fa.txt as copy of en.txt with all translations and edit and translate fa.txt to persian...
Hope it helps
#rbenmass
Thank You :-)
I think it have to be , because it runs good for me :
/*
original from #rbenmass :
function translate($q, $sl, $tl){
if($s==$e || $s=='' || $e==''){
return $q;
}
**/
function translate($q, $sl, $tl){
if($sl==$tl || $sl=='' || $tl==''){
return $q;
}
// ... //
I was wondering how would hide the text Location if the city state and country were not present and how would I let it display if any of the variables were present?
<p>Location:
<?php
if (!empty($city))
{
echo $city .',';
}
if (!empty($state))
{
echo $state;
}
if (!empty($country))
{
echo ' ' . $country;
}
?>
</p>
Use:
<?php
$address = "";
if (!empty($city))
{
$address_parts[] = $city;
}
if (!empty($state))
{
$address_parts[] = $state;
}
if (!empty($country))
{
$address_parts[] = $country;
}
$address = implode( ", ", $address_parts);
if (!empty($address))
{
echo "<p>Location: " . $address . "</p>";
}
?>
Build the address up and then test if the address is still empty before displaying location.
Edit
Changed how the address is built up. Rather than concatenate everything, the address parts are added to an array and then imploded with the appropriate separator.
Wrap it in a PHP block as well:
<?php
// Check if any of them is not empty.
if(!empty($city) || !empty($state) || !empty($country)){
echo "<p>Location:";
if (!empty($city))
{
echo $city .',';
}
if (!empty($state))
{
echo $state;
}
if (!empty($country))
{
echo ' ' . $country;
}
echo "</p>";
}
in not exactly same but a similar problem, i used this method.
may be this helps you too:)
<?php
function publish($buffer){
global $location;
if (empty($location))
$buffer="";
return $buffer;
}
ob_start("publish");
$location=$_GET["location"];
echo "Location: $location";
ob_end_flush();
?>
test the url with location parameter and without a parameter.
And you can find more detail about this in php.net output control functions