if I have a start date, say 2009-02-01 and an end date say 2010-01-01. How can I create a loop to go through all the dates (months) in the range?
Thanks!!
I have 3 featured product panels on the homepage, and I'm writing a CMS page for it. I'm trying to validate the items.
They are selected via three <select> elements, featured1, featured2 and featured3. The default is <option value="0" selected>Select an element</option>
I need to validate the $_POST to ensure that the user hasn't selected the same product for more than one of the panels.
I have worked out that each $_POST needs to be $_POST['featuredN'] > 0 but I can't seem to find a logical way of processing the 7 potential outcomes. Using a logic table, where 1 is a set value.
1 2 3
-------
0 0 0
1 1 1
1 0 0
0 1 0
0 0 1
1 1 0
0 1 1
If an item is 0, then I will not update it, but I want the user to be able to update a single item if needs be.
I cannot find a logical way to see if the item is not 0, and then compare it to another item if that also is not 0.
So far my colleague suggested, adding up the values. Which works to see if condition 1 0 0 0 is not met.
I have a vague feeling that some form of recursive function might be in order, but I can't quite get my brain to help me on this one! So to the collective brain! :)
I want to split text by the letter-followed-by-period rule. So I do this:
$text = 'One two. Three test. And yet another one';
$splitted_text = preg_split("/\w\./", $text);
print_r($splitted_text);
Then I get this:
Array ( [0] => One tw [1] => Three tes [2] => And yet another one )
But I do need it to be like this:
Array ( [0] => One two [1] => Three test [2] => And yet another one )
How to settle the matter?
I'm trying to get url links to those bit.ly redirects. I've tried to open bit.ly links with file_get_contents but it already gets content from redirected site, but how to get its url?
Hello guys I've got a mass mail function that sends e-mail to all emails in my mysql table. but theyr all goes spam. I want to use smtp validate for this function. How can I use smtp validation with "mail($email, $subject, $message, $headers);" ?
thank u
Hi, I'm trying to output lists of objects as json and would like to know if there's a way to make objects usable to json_encode? The code I've got looks something like
$related = $user->getRelatedUsers();
echo json_encode($related);
Right now, I'm just iterating through the array of users and individually exporting them into arrays for json_encode to turn into usable json for me. I've already tried making the objects iterable, but json_encode just seems to skip them anyway.
If I do the following (this is the actual/direct path to the JavaScript file):
<script href="http://localhost/tpl/blue/js/functions.js" type="text/javascript"></script>
It works fine, and the JavaScript parses - as its meant too.
However I'm wanting to shorten the path to the JavaScript file (aswell as do some caching) which is why I'm rewriting all JavaScript files via .htaccess to cache.php (which handles the caching).
The .htaccess contains the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^js/(.+?\.js)$ cache.php?file=$1 [NC]
</IfModule>
cache.php contains the following PHP code:
<?php
if (extension_loaded('zlib')) {
ob_start('ob_gzhandler');
}
$file = basename($_GET['file']);
if (file_exists("tpl/blue/js/".$file)) {
header("Content-Type: application/javascript");
header('Cache-Control: must-revalidate');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
echo file_get_contents("tpl/blue/js/".$file);
}
?>
and I'm calling the JavaScript file like so:
<script href="http://localhost/js/functions.js" type="text/javascript"></script>
But doing that the JavaScript doesn't parse? (if I call the functions which are within functions.js later on in the page they don't work) - so theirs a problem either with cache.php or the rewrite rule? (because the file by itself works fine).
If I access the rewrited file- http://localhost/js/functions.js directly it prints the JavaScript code, as any JavaScript file would - so I'm confused as to what I'm doing wrong...
All help is appreciated! :)
How can I know during runtime that my code threw a Warning?
example
try {
echo (25/0);
} catch (exception $exc) {
echo "exception catched";
}
throws a "Warning: Division by zero" error that i can not handle on my code.
Hello I'm getting a bunch of weird html output in users messages
e.g.
\u0644\u064a\u0646\u0643 \u0627\u0644 \u0639\u0627\u0645\u0644
I assume their aribic characters decoded?
How can I perhaps preg replace all these codes with something a little more useful? because search results are filled with pages and pages of this stuff
Perhaps even display them as they're supposed to be?
Any advice what to do with such strings and how to implement them appreciated..
Please keep in mind this stuff is mixed in been common language letters / numbers
many thanks
Hi everybody,
I have tried to get my head around building a recursive function to handle formatting of a unknown depth multi-dimensional array to HTML and nested Divs. I thought that it should be a piece of cake, but no.
Here's what I have come up with this far:
function formatHtml($array) {
$var = '<div>';
foreach ($array as $k => $v) {
if (is_array($v['children']) && !empty($v['children'])) {
formatHtml($v['children']);
}
else {
$var .= $v['cid'];
}
}
$var.= '</div>';
return $var;
}
And here's my array:
Array
(
[1] => Array
(
[cid] => 1
[_parent] =>
[id] => 1
[name] => 'Root category'
[children] => Array
(
[2] => Array
(
[cid] => 2
[_parent] => 1
[id] => 3
[name] => 'Child category'
[children] => Array ()
)
)
)
)
Thanks a lot!
I decided to make a recent view box that allows users to see what links they clicked on before. Whenever they click on a posting, the posting's id gets stored in a cookie and displays it in the recent view box.
In my ad.php, I have a definerecentview function that stores the posting's id (so I can call it later when trying to get the posting's information such as title, price from the database) in a cookie. How do I create a cookie array for this?
**EXAMPLE:** user clicks on ad.php?posting_id='200'
//this is in the ad.php
function definerecentview()
{
$posting_id=$_GET['posting_id'];
//this adds 30 days to the current time
$Month = 2592000 + time();
$i=1;
if (isset($posting_id)){
//lost here
for($i=1,$i< ???,$i++){
setcookie("recentviewitem[$i]", $posting_id, $Month);
}
}
}
function displayrecentviews()
{
echo "<div class='recentviews'>";
echo "Recent Views";
if (isset($_COOKIE['recentviewitem']))
{
foreach ($_COOKIE['recentviewitem'] as $name => $value)
{
echo "$name : $value <br />\n"; //right now just shows the posting_id
}
}
echo "</div>";
}
How do I use a for loop or foreach loop to make it that whenever a user clicks on an ad, it makes an array in the cookie? So it would be like..
1. clicks on ad.php?posting_id=200 --- setcookie("recentviewitem[1]",200,$month);
2. clicks on ad.php?posting_id=201 --- setcookie("recentviewitem[2]",201,$month);
3. clicks on ad.php?posting_id=202 --- setcookie("recentviewitem[3]",202,$month);
Then in the displayrecentitem function, I just echo however many cookies were set?
I'm just totally lost in creating a for loop that sets the cookies. any help would be appreciated
I'm seeking a portable way to receive the (handy) $_SERVER['PATH_INFO'] variable.
After reading a while, it turns out PATH_INFO is originated from CGI/1.1, and my not always be present in all configuration.
What is the best (mostly security-wise) way to get that variable - apart from extracting it manually (security concern).
Hello
i need to refresh combo box (sub category ) related to what i choose in main category combo box , for example if i choose "chicken" in main category , the value of sub category will be "grilled chicken" , " fried chicken " ? how should i do this ?
<select name="categorylist" id="categorylist">
<?
$sql_query= mysql_query("select category_id,category_name, from categories");
while($fetch= mysql_fetch_array($sql_query))
{ ?>
<option value= " <? echo "$fetch[category_id];" ?> " selected="selected"><? echo "$fetch[category_name]"; ?> </option>
<?
}
?>
what should i put in subcategory ?
Hello,
I'm hoping somebody knows the answer :).
Within wordpress in the users section I would like to add a new row which will data pulled in from the Register Plus plugin.
Where would I need to create a new row?
My Example:
Username Name E-mail Role **Website** Posts
Admin Admin [email protected] Administrator google.com 2
Thanks.
$tagArray = array(
"apples" => 12,
"oranges" => 38,
"pears" => 10,
"mangos" => 24,
"grapes" => 18,
"bananas" => 56,
"watermelons" => 80,
"lemons" => 12,
"limes" => 12,
"pineapples" => 15,
"strawberries" => 20,
"coconuts" => 43,
"cherries" => 20,
"raspberries" => 8,
"peaches" => 25
);
and how i can do this in java, and how to calling for the first and second params?
Hi, for a certain project, I need some way to parse XML and get data from it. So I wonder, which one of built-in parsers is the fastest?
Also, it would be nice of the parser could accept a XML string as input - I have my own implementation of thread-safe working with files and I don't want some nasty non-thread-safe libraries to make my efforts useless.
I have zlib and Zend Optimizer enabled on my server.
I have read about the
zlib.output_compression
directive. Are there any caveats with turning this directive on in my server?
Using PHP5 and the latest version of MySQL I want to be able to track impressions and clicks for business listings. My question is if I did this myself what would be the best method in storing it so I can run reports? Before I just had a table that had the listing id, user ip address and if it was a click or impression as well as the date it was tracked. However the database itself is approaching 2GB of data and its very slow, part of the problem is its a pretty simple script that includes impressions and clicks from anyone including search engines and basically anyone or anything that accesses the listing page.
Is there an api or file out there that has an update to date list that can detect if the person viewing is a actually person and not a spider so I dont fill up the database with unneeded stats? Just looking for suggestions, do I just have a raw database that gets just the hits then a cron job at night tally up for the day for each listing for each ip and store the cumulative stats in a different table?
Also what type of database should it be? Innodb? MyISAM?
Hi,
I'm basically trying to convert a Unix timestamp (the time() function) to a relative date/time that's both compatible with past and future date. So outputs could be:
2 weeks ago
1 hour and 60 minutes ago
15 minutes and 54 seconds ago
after 10 minutes and 15 seconds
First I tried to code this, but made a huge unmaintainable function, and then I searched the internet for a couple of hours, yet all I can find are scripts that produce only one part of the time (e.h: "1 hour ago" without the minutes).
Do you have a script that already does this? If so, I'd really appreciate if you could share it.
Thanks.
Been battling with this one for what seems, like forever.
I have an array:
$url_array
It contains this info:
Array (
[ppp] => Array (
[0] => stdClass Object (
[id] => 46660
[entity_id] => 0
[redirect_url] => http://www.google.com
[type] => Image
)
[1] => stdClass Object (
[id] => 52662
[entity_id] => 0
[pixel_redirect_url] => http://www.yahoo.com
[type] => Image
)
[2] => stdClass Object (
[id] => 53877
[entity_id] => 0
[redirect_url] => http://www.msn.com
[pixel_type] => Image
)
)
[total_count] => 3
)
I need to loop through it, and do things to each variable. I can get this to work:
foreach ($piggies_array as $key => $value) {
$id = $value[0]->id;
$redirect_url = $value[0]->redirect_url; }
Not unsurprisingly, it's only echoing the first value of those variables, but no matter what I try I cannot get it to loop through:
$value->redirect_url;
$value=>redirect_url;
I would appreciate any help.
I'm writing a little homebrew ORM (academic interest). I'm trying to adhere to the TDD concept as a training exercise, and as part of that exercise I'm writing documentation for the API as I develop the class.
Case in point - I'm working on a classic "getCollection" type mapper class. I want it to be able to retrieve collections of asset X (let's say blog posts) for a specific user, and also collections based on an arbitrary array of numeric values. So - you might have a method like any one of these
$User = $UserMapper->load(1);
$ArticleCollection = $ArticleMapper->getCollection(range(10,20));
$ArticleCollection = $ArticleMapper->getCollection($User);
$ArticleCollection = $ArticleMapper->getCollection($User->getId());
So, in writing the documentation for the getCollection method - I want to declare the @param variable in the Docblock. Is it better to have a unique method for each argument type, or is it acceptable to have a method that delegates to the correct internal method/class based on argument type?
Introduction:
I want to loop through XML files with flexible categories structure.
Problem:
I don't know to loop through a theoretical infinte subcategories without having to make x amount of "for each" statements (See coding example in the bottom). How do I dynamically traverse the categories structure?
What I have now:
I have no problem looping through XML files with a set structure:
<catalog>
<category name="Category - level 1">
<category name="Category - level 2">
<category name="Category - level 3" />
</category>
<category name="Category - level 2">
<category name="Category - level 3" />
</category>
</category>
</catalog>
Coding example:
//$xml holds the XML file
foreach ( $xml AS $category_level1 )
{
echo $category_level1['name'];
foreach ( $category_level1->category AS $category_level2 )
{
echo $category_level2['name'];
foreach ( $category_level2->category AS $category_level3 )
{
echo $category_level3['name'];
}
}
}