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!!
Hi my question
Need to get the 10 word before and 10 words after for the given text . i mean need to start the 10 words before the keyword and end with 10 word after the key word.
Given text : "Twenty-three"
The main trick : content having some html tags etc .. tags need to keep that tag with this content only . need to display the words from 10before - 10after
content is bellow :
<div id="hpFeatureBoxInt"><h3><a href="/go/homepage/i/int/news/world/1/-/news/1/hi/world/europe/8592190.stm">Suicide bombings hit Moscow Metro</a></h3><p>Past suicide bombings in Moscow have been blamed on Islamist rebels At least 35 people have been killed after two female suicide bombers blew themselves up on Moscow Metro trains in the morning rush hour,<h2><span class="dy">Top News Story</span></h2> officials say.<img height="150" width="201" alt="Emergency services carry a body from a Metro station in Moscow (29 March 2010)" src="http://wwwimg.bbc.co.uk/feedengine/homepage/images/_47550689_moscowap203_201x150.jpg">Twenty-three died in the first blast at 0756 (0356 GMT) as a<a href="#"> train stood </a>at the central Lubyanka station, beneath the offices of the FSB intelligence agency.About 40 minutes later, a second explosion ripped through a train at Park Kultury, leaving another 12 dead.No-one has said they carried out the worst attack in the capital since 2004. </p><p id="fbilisten"><a href="/go/homepage/i/int/news/heading/-/news/">More from BBC News</a></p></div>
Thank you
I have a form at the bottom of a long page, if a user fills out the form but it doesn't validate the page is reloaded in the typical codeigniter fashion:
$this->load->view('template',$data);
however because the form is way down at the bottom of the page I need the page to load down there like you do with HTML anchors. Does anyone know how to do this in codeigniter?
I can't use the codeigniter
redirect();
function because it loses the object and the validation errors are gone. Other frameworks I've used like Yii you can call the redirect function like:
$this->redirect();
which solves the problem because you keep the object. I've tried using:
$this->index()
within the controller which works fine as a redirect but the validation errors are in another method which is where the current page is loaded from:
$this->item($labs)
but when I use this it get stuck in a loop
Any ideas? I've seen this question a lot on the net but no clear answers. I'm researching using codeigniter "flash data" but think it's a bit overkill.
cheers.
Let's say I have a data mapper function that aggregates multiple tables and generates an object instance from that data. The mapper has a typical save() method which delegates to update/insert.
When the mapper executes save - ideally it isolates object fields that have been modified, thus preventing the code from blanket bombing the database.
How would you go about this?
I have the following:
echo time()."<br>";
sleep(1);
echo time()."<br>";
sleep(1);
echo time()."<br>";
I wrote the preceding code with intention to echo time()."<br>" ln 1,echo time()."<br>" ln 4, wait a final second and then echo the final time()."<br>". Altough the time bieng echoed is correct when it comes to the intervals between time(), all echo functions are echoeing after the total of the waiting period/parameters in each sleep function.
This is how the script runs:
Excutes.
Waits 2 secons.
echoes
1275540664
1275540665
1275540666
Notice the correct incrementation in time() being echoed. My question is why is it not behaving like expected to where it echoes, waits a second, echoes again, waits one final second and then echos the last parameter?
I know my question is a little confusing due to my wording, but i will try my hardest to answer any comments regarding this, 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 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! :)
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.
Fatal error:
Call to undefined function mb_substr()
after moving to my dedicated server (hypervm CP) , i got lots of errors .
it would be grateful ,if you know how to solve this problem
thanks in advance
I'm running the following code over a set of 5,000 results. It's failing due to the memory being exhausted.
foreach ($data as $key => $report) {
$data[$key]['data'] = unserialize($report['serialized_values']);
}
I know I can up the memory limit, but I'd like to run this without a problem instead. I'm not going to be able to keep upping the memory forever.
EDIT
The $data is in this format:
[1] => Array
(
[0] => 127654619178790249
[report_id] => 127654619178790249
[1] => 1
[user_id] => 1
[2] => 2010-12-31 19:43:24
[sent_on] => 2010-12-31 19:43:24
[3] =>
[fax_trans_id] =>
[4] => 1234567890
[fax_to_nums] => 1234567890
[5] => ' long html string here',
[html_content] => 'long html string here',
[6] => 'serialization_string_here',
[serialized_values] => 'serialization_string_here',
[7] => 70
[id] => 70
)
I'm working on a calendar app and need to get the timestamps for the beginning of each day/month etc:
whats the best method?
//get timestamps for start of (day, month, year)
$ts_now = time();
$ts_today =
$ts_this_month =
$ts_this_year =
Hi guys. Might be an easy question for you guys. can't find it on google.
I am trying to concatenate two variables name;
$i=0;
for ($i=0;$i<5;$i++){
if($array[$i]>0){
$test.$i=//do something
}else{
$test.$i=//do something
}
}
//echo $test0 gives me nothing.
//echo $test1 gives me nothing.
I know I can't use $test.$i but don't know how to do this.Any helps? Thanks!
Hello,
I have a news site containing an archive with more than 1 million news.
I created a word definitions database with about 3000 entries, consisting of word-definition pairs.
What I want to do is adding a definition next to every occurence of these words in the news.
I cant make a static change as I can add a new keyword everyday, so i can make it realtime or cached.
The question is, a str_replace or a preg_replace would be very slow for searching 3 thousand keywords in a text and replacing them.
Are there any fast alternatives?
I am currently working on a project that extensively relies on the EAV model. Both entities as their attributes are individually represented by a model, sometimes extending other models (or at least, base models).
This has worked quite well so far since most areas of the application only rely on filtered sets of entities, and not the entire dataset.
Now, however, I need to parse the entire dataset (IE: all entities and all their attributes) in order to provide a sorting/filtering algorithm based on the attributes.
The application currently consists of aproximately 2200 entities, each with aproximately 100 attributes. Every entity is represented by a single model (for example Client_Model_Entity) and has a protected property called $_attributes, which is an array of Attribute objects.
Each entity object is about 500KB, which results in an incredible load on the server. With 2000 entities, this means a single task would take 1GB of RAM (and a lot of CPU time) in order to work, which is unacceptable.
Are there any patterns or common approaches to iterating over such large datasets? Paging is not really an option, since everything has to be taken into account in order to provide the sorting algorithm.
Hello,
I have a script that each time is called gets the 1st line of a file. Each line is known to be exactly of the same length (32 alphanumerci chars) and terminates with a "\r\n".
After getting the 1st line, the script removes it.
Now I do in this way:
$contents = file_get_contents($file));
$first_line = substr($contents, 0, 32);
file_put_contents($file, substr($contents, 32 + 2)); //+2 because we remove also the \r\n
Obvioulsy it works, but I was wondering if there could be a smarter (or more efficent) way to do this???
In my simple solution I basically read and rewrite all the file just to take and remove the 1st line.
Thanks!
Hi,
I need to integrate the Web cam to the application. I need to take the user profile picture using the web cam. How can i do that. any one can help me?
Thanks in advance,
I am using this to get real IP but i take empty from $_SERVER['HTTP_CLIENT_IP'],i take not empty only from $_SERVER['REMOTE_ADDR'].But i dont need the IP of proxy,i need the real ip of computers using some intranet.Can i get it?when $_SERVER['HTTP_CLIENT_IP'] does not return empty?
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
I have a membership based website and im planning on implementing a referral system.
My website is credit based, the idea is that if User X refers User Y, then User X gets 100 bonus credits.
Has anybody built a referral system before and if so what obstacles should I bear in mind? I've had a snoop round SO tonight but couldn't find any suitable answers.
My theory is to give each user a random string which is generated and stored in the DB when they sign up, The user will then be presented with a URL incl. that string which when they pass to somebody (User Z), User Z is then sent to a page, the page then uses the GET method to gather the Random string and update the DB Row they currently occupy, does this sound feasible or could it easily be breached?
Thanks
Hello in my database date / time are stored in this format
2010-06-01T18:20:25+0000
I'd like to echo that out to time passed since that date / time
e.g.
2 minutes ago or 2 days ago
is this possible?
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.
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?
My English is poor so I will make it short.
Right now, I have imzip.zip which has three txt files:
a.txt
b.txt
c.txt
When I try to load imzip.zip using:
http://pastebin.com/m1d974990
It loads the files alphabetically. In this case:
a.txt
b.txt
c.txt
However, I would like to be able to have the class load on different variables such as by size, date or simply random.
The problem is I have no idea how I would go about modifying the class to fit my needs.
I would really appreciate your help! :D
How do I get this to not display when you first go to the page???
if ($error) {
echo "Error: $error<br/>";
}
if ($keycode) {
echo "Keycode: $keycode<br/>";
}