help me please,, syntax eror
$Prodi = array("Ilmu Hukum" => array("Angkatan 2010" => array("Siswono","Hariono","Madun"),
"Teknik Informatika" => array("Angkatan 2010" => array("Atep","Ferdinan","I Made"),
"Akutansi" => array("Angkatan 2010" => array("Ridwan","Firman","Zulkifli")))));
while(list($key1) = each($Prodi)) {
echo "$key1 : <br>";
}
while(list($key2,$val) = each($Prodi["$key1"])){
echo "-$val<br>";
}
While(list($key3,$val) = each($Prodi["$key2"])){
echo "-$val<br>";
}
You may use the following code.
foreach($Prodi as $a1key => $a1val) {
echo $a1key . '===' . json_encode($a1val) . '<br />';
foreach($a1val as $a2key => $a2val) {
echo $a2key . '===' . json_encode($a2val) . '<br />';
foreach($a2val as $a3key => $a3val) {
echo $a3key . '===' . json_encode($a3val) . '<br />';
}
}
}
Related
I have a multistep form (HTML / JS / PHP) and the form data gets sent to a backend after submitting, which results in a page reload.
Is it possible to pass the data live to the backend when the user gets to a new page of the form (clicks on the next button)?
<?php
require_once dirname(__FILE__) . '/MailWizzApi/Autoloader.php';
MailWizzApi_Autoloader::register();
// configuration object
$config = new MailWizzApi_Config(array(
'apiUrl' => 'http://email.mddasd.de/api/index.php',
'publicKey' => 'SAMPLEKEY',
'privateKey' => 'SAMPLEKEY',
// components
'components' => array(
'cache' => array(
'class' => 'MailWizzApi_Cache_File',
'filesPath' => dirname(__FILE__) . '/MailWizzApi/Cache/data/cache', // make sure it is writable by webserver
)
),
));
// now inject the configuration and we are ready to make api calls
MailWizzApi_Base::setConfig($config);
// start UTC
date_default_timezone_set('UTC');
$email = $_POST ['email'];
$name = $_POST['name'];
$phone = $_POST['telephone'];
if (isset($_POST['branch_0_answers']) && $_POST['branch_0_answers'] != "")
{
foreach($_POST['branch_0_answers'] as $value)
{
$art.= trim(stripslashes($value)) . "\n";
};
$grundflaeche .= $_POST['grundflaeche-grundstueck'] . "\n";
$plz .= $_POST['plz'] . "\n";
}
if (isset($_POST['branch_1_answers']) && $_POST['branch_1_answers'] != "")
{
foreach($_POST['branch_1_answers'] as $value)
{
$art.= trim(stripslashes($value)) . "\n";
};
$wohnflaeche .= $_POST['wohnflaeche-haus'] . "\n";
$grundflaeche .= $_POST['grundflaeche-haus'] . "\n";
$baujahr .= $_POST['baujahr'] . "\n";
$plz .= $_POST['plz'] . "\n";
}
if (isset($_POST['branch_2_answers']) && $_POST['branch_2_answers'] != "")
{
foreach($_POST['branch_2_answers'] as $value)
{
$art.= trim(stripslashes($value)) . "\n";
};
$wohnflaeche .= $_POST['wohnflaeche-wohnung'] . "\n";
$baujahr .= $_POST['baujahr'] . "\n";
$plz .= $_POST['plz'] . "\n";
}
if (isset($_POST['branch_3_answers']) && $_POST['branch_3_answers'] != "")
{
foreach($_POST['branch_3_answers'] as $value)
{
$art.= trim(stripslashes($value)) . "\n";
};
$gewerbeflaeche .= $_POST['gewerbeflaeche'] . "\n";
$grundflaeche .= $_POST['grundflaeche-gewerbe'] . "\n";
$baujahr .= $_POST['baujahr'] . "\n";
$plz .= $_POST['plz'] . "\n";
}
foreach($_POST['branch_1_1_answers'] as $value)
{
$stand.= trim(stripslashes($value)) . "\n";
};
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();
$response = $endpoint->create('ma503j6m97b75', array(
'EMAIL' => $email,
'TELEFON' => $phone,
'NAME' => $name,
'ART' => $art,
'GEWERBEFLAECHE' => $gewerbeflaeche,
'WOHNFLAECHE' => $wohnflaeche,
'GRUNDFLAECHE' => $grundflaeche,
'BAUJAHR' => $baujahr,
'PLZ' => $plz,
'STAND' => $stand
));
?>
The .php gets executed with the final submit button.
Thanks for your answers.
I am trying to speed up the time it takes me to launch instances from a specific AMI using this AWS blog post as a starting point, however I am not sure how to grab the ID of the newly acquired Instance I have spun up using V3 of the PHP API (opposed to V2 in the blog post) so I can retrieve further information about the Instance (using the ID I would have retrieved)
<?php
require 'C:\wamp\bin\php\php5.5.12\vendor\autoload.php';
use Aws\Ec2\Ec2Client;
$ec2Client = \Aws\Ec2\Ec2Client::factory(array(
'region' => 'eu-west-1',
'version' => 'latest'
));
//Default vars
$aws_key = 'aws-ireland';
$ami_id = 'ami-000000';
$min_count = '1';
$max_count = '1';
$instance_type = 't2.micro';
$instance_region = 'eu-west-1b';
$server_name = 'API Test Server';
$result = $ec2Client->runInstances(array (
//Creating the instance
'KeyName' => $aws_key,
'ImageId' => $ami_id,
'MinCount' => $min_count,
'MaxCount' => $max_count,
'InstanceType' => $instance_type,
'Placement' => array('AvailabilityZone' => $instance_region),
));
//Wait for server to be created
//Return the instance ID
Following the blog post any further from this results in errors as the method waitUntilInstanceRunning doesn't exist in V3 of the API. I believe I need to use a waiter, but I'm not sure how I would use this for my problem?
What about this:
$result = $aws->DescribeInstances();
$reservations = $result['Reservations'];
foreach ($reservations as $reservation) {
$instances = $reservation['Instances'];
foreach ($instances as $instance) {
$instanceName = '';
foreach ($instance['Tags'] as $tag) {
if ($tag['Key'] == 'Name') {
$instanceName = $tag['Value'];
}
}
echo 'Instance Name: ' . $instanceName . PHP_EOL;
echo '<br>';
echo '---> State: ' . $instance['State']['Name'] . PHP_EOL;
echo '<br>';
echo '---> Instance ID: ' . $instance['InstanceId'] . PHP_EOL;
echo '<br>';
echo '---> Image ID: ' . $instance['ImageId'] . PHP_EOL;
echo '<br>';
echo '---> Private Dns Name: ' . $instance['PrivateDnsName'] . PHP_EOL;
echo '<br>';
echo '---> Instance Type: ' . $instance['InstanceType'] . PHP_EOL;
echo '<br>';
echo '---> Security Group: ' . $instance['SecurityGroups'][0]['GroupName'] . PHP_EOL;
echo '<br>';
echo '-----------------------------------------------------------------------------------------------------';
echo '<br>';
echo '<br>';
}
}
I am trying to download all my listings from ebay into my database using following code:
$client = new eBaySOAP($session);
$ebay_items_array = array();
try {
$client = new eBaySOAP($session);
$params = array(
'Version' => $Version,
'GranularityLevel' => "Fine",
'OutputSelector' => "ItemID,SKU,Title",
'EndTimeFrom' => date("c", mktime(date("H"), date("i")+10, date("s"), date("n"), date("j"), date("Y"))),
'EndTimeTo' => date("c", mktime(date("H"), date("i"), date("s"), date("n"), date("j")+120, date("Y"))),
'Pagination' => array(
'PageNumber' => $_GET['linkebaynum'],
'EntriesPerPage' => "20"
)
);
$results = $client->GetSellerList($params);
if($results->Ack == "Success")
{
$c = 0;
if(is_array($results->ItemArray->Item))
{
foreach($results->ItemArray->Item as $key => $value)
{
array_push($ebay_items_array, $value->ItemID);
$Qcheck = tep_db_query('select ebay_productstoitems_items_id from ' . TABLE_EBAY_PRODUCTS_TO_ITEMS . ' where ebay_productstoitems_items_id = ' . $value->ItemID);
$check = tep_db_fetch_array($Qcheck);
if($check == 0) {
if($check['ebay_productstoitems_items_id'] = $value->ItemID) {
echo 'Not in Database - Inserting ' . $value->ItemID . '<br>';
tep_db_query("insert ebay_productstoitems set ebay_productstoitems_items_id = '" . $value->ItemID . "'");
}
}else{
echo 'Found - ' . $value->ItemID . ' Nothing to Change<br>';
tep_db_query("update ebay_productstoitems set ebay_productstoitems_items_id = '" . $value->ItemID . "' where ebay_productstoitems_items_id = '" . $value->ItemID . "'");
}
}
$c++;
}
}
} catch (SOAPFault $f) {
print "error<br>";
}
print "Request:<br>".ebay_formatxmlstring($client->__getLastRequest())."<br><br>";
print "Response:<br>".ebay_formatxmlstring($client->__getLastResponse())."<br><br>";
But it will not recover the SKU (or CustomLabel).
Can anyone explain what I am missing to get the SKU into the database along with the ItemID.
Or would I have to recover lists of ItemID and then do a second call to recover the SKU or CustomLabel?
Found out what the problem was the Sandbox does not appear to pass the SKU back. I switched to the live site and hey presto the SKU is being retrieved along with the Itemid.
I'm trying to create functions dynamically with eval(). But I get this warning: Notice: Use of undefined constant Any suggestion?
$funcs = array('func_a', 'func_b', 'func_c');
foreach($funcs as $func_name) {
eval( 'function ' . $func_name . '() {
mainfunc(' . $func_name . ');
}'
);
}
func_a();
func_b();
func_c();
function mainfunc($func_name) {
echo $func_name . '<br />';
}
Assuming the array $func is an option value stored in a database and I need the function names for a callback function in a separate part of the script. So creating anonymous functions with create_function() is not what I'm looking for.
Thanks for your info.
Use better approach than eval(), it is called overloading.
Example:
class MainFunc {
public function __call($name, $arguments)
{
echo "_call($name)<br>";
}
public static function __callStatic($name, $arguments)
{
echo "_callStatic($name)<br>";
}
}
# php >= 5.4.x
(new MainFunc)->func_a();
(new MainFunc)->func_b("param", "param2");
# or php < 5.4
$mainFunc = new MainFunc;
$mainFunc->func_a();
$mainFunc->func_b("param", "param2");
MainFunc::func_a_static();
MainFunc::func_b_static("param", "param2");
Output is:
_call(func_a)
_call(func_b)
_callStatic(func_a_static)
_callStatic(func_b_static)
Your eval body needs to read:
mainfunc(\'' . $func_name . '\');
Without the single quotes, eval() makes code that has an unquoted literal--an undefined constant.
For those who were wondering what I was talking about, here is the sample WordPress plugin which demonstrates how dynamic function creation comes handy.
/* Plugin Name: Sample Action Hooks with Dynamic Functions */
// assuming this is an option retrieved from the database
$oActions = array( 'a' => array('interval' => 10, 'value' => 'hi'),
'b' => array('interval' => 30, 'value' => 'hello'),
'c' => array('interval' => 60, 'value' => 'bye')
);
add_action('init', LoadEvents);
function LoadEvents() {
global $oActions;
foreach($oActions as $strActionName => $array) {
eval( 'function ' . $strActionName . '() {
SampleEvents(\'' . $strActionName . '\');
}'
);
add_action('sampletask_' . md5($strActionName), $strActionName);
if (!wp_next_scheduled( 'sampletask_' . md5($strActionName)))
wp_schedule_single_event(time() + $oActions[$strActionName]['interval'], 'sampletask_' . md5($strActionName));
}
}
function SampleEvents($strActionName) {
global $oActions;
// just log for a demo
$file = __DIR__ . '/log.html';
$current = date('l jS \of F Y h:i:s A') . ': ' . $strActionName . ', ' . $oActions[$strActionName]['value'] . '<br />' . PHP_EOL;
file_put_contents($file, $current, FILE_APPEND);
wp_schedule_single_event(time() + $oActions[$strActionName]['interval'], 'sampletask_' . md5($strActionName));
}
And the same functionality could be achieved with __call().
/* Plugin Name: Sample Action Hooks */
add_action('init', create_function( '', '$oSampleEvents = new SampleEvents;' ));
class SampleEvents {
public $oActions = array( 'a' => array('interval' => 10, 'value' => 'hi'),
'b' => array('interval' => 30, 'value' => 'hello'),
'c' => array('interval' => 60, 'value' => 'bye')
);
function __construct() {
foreach($this->oActions as $strActionName => $arrAction) {
add_action('sampletask_' . md5($strActionName), array(&$this, $strActionName));
if (!wp_next_scheduled( 'sampletask_' . md5($strActionName)))
wp_schedule_single_event(time() + $this->oActions[$strActionName]['interval'], 'sampletask_' . md5($strActionName));
}
}
function __call($strMethodName, $arguments) {
// just log for a demo
$file = __DIR__ . '/log.html';
$current = date('l jS \of F Y h:i:s A') . ': ' . $strMethodName . ', ' . $this->oActions[$strMethodName]['value'] . '<br />' . PHP_EOL;
file_put_contents($file, $current, FILE_APPEND);
wp_schedule_single_event(time() + $this->oActions[$strMethodName]['interval'], 'sampletask_' . md5($strMethodName));
}
}
I was using this to generate RSS to post to my facebook wall... but in the last 24 hours it stopped working. I think that the feed pushing service i use became strict with the RSS validation. This doesnt validate... and i cant get it too. Can anyone suggest changes to make this work? I know this probably looks VERY messy! :os
Thanks in advance.
<?php do { ?>
<item>
<title><![CDATA[<?php echo htmlentities(strip_tags(addslashes($row_getDresses['listing_title']))); ?><?php if($_GET['type'] == "reduced-dresses"){?> (REDUCED BY <?php echo $row_getDresses['symbol'];?><?php echo $row_getDresses['reduced_price'];?> <?php echo $row_getDresses['dress_currency'];?>)<?php } else {?> (<?php echo $row_getDresses['symbol'];?><?php echo $row_getDresses['price'];?> <?php echo $row_getDresses['dress_currency'];?>)<?php }?>]]></title>
<link><![CDATA[http://www.asite.com/dress/<?php echo $row_getDresses['listing_tidy_url'];?>-<?php echo $row_getDresses['dress_id'];?>.html]]></link>
<description><![CDATA[<?php echo substr(strip_tags(addslashes(trim($row_getDresses['dress_desc'])),'ENT_QUOTES'),0,100);?>]]>...</description>
<?php if (isset($row_getDresses['main_image']) && file_exists("../listing-images/".$row_getDresses['main_image']."")) { ?>
<enclosure url="http://www.asite.com/listing-images/<?php echo $row_getDresses['main_image'];?>" length="<?php echo filesize("../listing-images/".$row_getDresses['main_image']."");?>" type="image/jpeg">
<?php }?>
<?php if ($_GET['type'] == "reduced-dresses"){?>
<pubDate><?php echo $row_getDresses['date_updated'];?> GMT</pubDate>
<?php } else { ?>
<pubDate><?php echo $row_getDresses['date_added'];?> GMT</pubDate>
<?php }?>
<category><?php echo htmlentities($pageTitle);?></category>
</item>
<?php } while ($row_getDresses = mysql_fetch_assoc($getDresses)); ?>
you dosn't close the enclosure-tag, add a </enclosure> or just add a / at the end of the tag like <enclosure ... />
Update
and readability was horible, here is an exemple at your code in my coding-style:
<?php
do
{
/* preper data */
$category = htmlentities($pageTitle);
$link = "http://www.asite.com/dress/{$row_getDresses['listing_tidy_url']}-{$row_getDresses['dress_id']}.html";
$description = substr(strip_tags(addslashes(trim($row_getDresses['dress_desc'])),'ENT_QUOTES'),0,100);
$title = htmlentities(strip_tags(addslashes($row_getDresses['listing_title'])));
/* Reduced price? */
if($_GET['type'] == "reduced-dresses")
{
$title .= " (REDUCED BY {$row_getDresses['symbol']}{$row_getDresses['reduced_price']} {$row_getDresses['dress_currency']})";
$date = $row_getDresses['date_updated'];
}
else
{
$titlt .= " ({$row_getDresses['symbol']}{$row_getDresses['price']} {$row_getDresses['dress_currency']})";
$date = $row_getDresses['date_added'];
}
/* image exists? */
if(isset($row_getDresses['main_image']) AND file_exists("../listing-images/".$row_getDresses['main_image'].""))
{
$image = "http://www.asite.com/listing-images/{$row_getDresses['main_image']}";
$image_size = filesize("../listing-images/".$row_getDresses['main_image']."");
}
else
{
$image = FALSE;
}
/* write RSS */
echo "<item>";
echo "<title><![CDATA[{$title}]]></title>";
echo "<link><![CDATA[{$link}]]></link>";
echo "<description><![CDATA[{$description}]]>...</description>";
if($image)
{
echo "<enclosure url='{$image}' length='{$image_size}' type='image/jpeg' />";
}
echo "<pubDate>{$date} GMT</pubDate>";
echo "<category>{$category}</category>";
echo "</item>";
} while ($row_getDresses = mysql_fetch_assoc($getDresses));
?>
I tried to make it a bit more readable and yes, enclosure was not closed:
<?php
$new_rss = '';
do {
$new_rss .= '<item>';
$new_rss .= '<title><![CDATA[' . htmlentities( strip_tags( addslashes( $row_getDresses[ 'listing_title' ] ) ) );
if( $_GET[ 'type' ] == 'reduced-dresses') {
$new_rss .= '(REDUCED BY ' . $row_getDresses[ 'symbol' ] . $row_getDresses[ 'reduced_price' ] . $row_getDresses[ 'dress_currency' ] . ')';
} else {
$new_rss .= '(' . $row_getDresses[ 'symbol' ] . $row_getDresses[ 'price' ] . $row_getDresses[ 'dress_currency' ] . ')';
}
$new_rss .= ']]></title>';
$new_rss .= '<link><![CDATA[http://www.asite.com/dress/' . $row_getDresses[ 'listing_tidy_url' ] . '-' . $row_getDresses[ 'dress_id' ] . '.html]]></link>';
$new_rss .= '<description><![CDATA[' . substr( strip_tags( addslashes( trim( $row_getDresses[ 'dress_desc' ] ) ), 'ENT_QUOTES' ), 0, 100 ) . ']]>...</description>';
if ( isset( $row_getDresses[ 'main_image' ] ) && file_exists( '../listing-images/' . $row_getDresses[ 'main_image' ] ) ) {
$new_rss .= '<enclosure url="http://www.asite.com/listing-images/' . $row_getDresses[ 'main_image' ] . '" length="' . filesize( '../listing-images/' . $row_getDresses[ 'main_image' ] ) . '" type="image/jpeg" />';
}
if ( $_GET[ 'type' ] == 'reduced-dresses' ) {
$new_rss .= '<pubDate>' . $row_getDresses[ 'date_updated' ] . ' GMT</pubDate>';
} else {
$new_rss .= '<pubDate>' . $row_getDresses[ 'date_added' ] . ' GMT</pubDate>';
}
$new_rss .= '<category>' . htmlentities($pageTitle) . '</category>';
$new_rss .= '</item>';
} while ( $row_getDresses = mysql_fetch_assoc( $getDresses ) );
echo $new_rss;
?>