i need some code which can delete/filter arrays which doesn't contain a specific word
or we can say keep only that contain a specific word and drop all other ones
so I have lots of users posting articles with names in different languages. I need some lib to translate thouse article names to english letters for example turn russian '?' into eng 'r' and so on for all european languages, russian and asian languages. Where to get such lib?
Hi Guys.
In some part of my code I need something like this:
$product_type = $product->type;
$price_field = 'field_'.$product_type.'_price';
$price = $product->$$price_field;
In other words I need kind of KVC - means get object field by field name produced at the runtime.
I simply need to extend some existing system and keep field naming convention so do not advice me to change field names instead.
I know something like this works for arrays, when you could easily do that by:
$price = $product[$price_field_key].
So I can produce key for array dynamically.
But how to do that for objects?
Please help me as google gives me river of results for arrays, etc...
Thank you
I've used mime_content_type() and File info but i never successed. i want to use now cURL and get the headers of the file which is hosted on another domain then determine if the type is MP3 or not. ( i think the mime type of MP3 is audio/mpeg)
Briefly, i know that but i don't know how to apply it :)
Thanks
What is the correct way to log out of HTTP authentication protected folder?
There are workarounds that can achieve this, but they are potentially dangerous because they can be buggy or don't work in certain situations / browsers. That is why I am looking for correct and clean solution.
Im using the Twitter API to collect the number of tweets I've favorited, well to be accurate the total pages of favorited tweets.
I use this URL: http://api.twitter.com/1/users/show/username.xml
I grab the XML element 'favorites_count'
For this example lets assume favorites_count=5
The Twitter API uses this URL to get the favorties: http://twitter.com/favorites.xml (Must be authenticated)
You can only get the last 20 favorties using this URL, however you can alter the URL to include a 'page' option by adding: ?page=3 to the end of the favorites URL e.g.
http://twitter.com/favorites.xml?page=2
So what I need to do is use CURL (I think) to collect the favorite tweets, but using the URL:
http://twitter.com/favorites.xml?page=1
http://twitter.com/favorites.xml?page=2
http://twitter.com/favorites.xml?page=3
http://twitter.com/favorites.xml?page=4
etc...
Some kind of loop to visit each URL, and collect the Tweets and then output the cotents.
Can anyone help with this:
- Need to use CURL to authenticate
- Collect the number of pages of tweets (Already scripted this)
- Then use a loop to go through each page URL based on the pages value?
I have found similar answers to my current needs on SO, however I am still trying to grasp modifying strings based on a rule, except in certain enclosures within those strings.
Example of what Im trying to accomplish now:
preg_replace("/\s*,\s*/", ",", $text)
I found the above in many places. It will remove spaces before and after all commas in a string.
That works great. However, if I want to exclude modifying commas found within " ", I am not sure how that rule has to be modified.
Any help? Thanks!
EDIT: I want to clarify my question:
I would like all whitespace before and after the commas in the following sentence removed, except commas found in double or single quotes:
a, b , c "d, e f g , " , h i j ,k lm,nop
Expected result:
a,b,c "d, e f g , ",h i j,k lm,nop
$_SERVER['REMOTE_USER'] returns the username of the user logged in to an Active Directory. I want to retrive this users info by using ldap_search().
This is what I have now:
$ad = // ldap_connection id
$filter = "(|(sn=$username*)(givenname=$username*))";
$attr = array("displayname", "mail", "mobile", "homephone", "telephonenumber", "streetaddress", "postalcode", "physicaldeliveryofficename", "l");
$dn = // OU, DC etc..
ldap_search($ad,$dn,$filter,$attr);
It works, but i'm not sure it will work if two users have almost the same names.
How do I only search for their unique username so that i always only get one user?
Hi Guys,
Consider these three mysql statements:
select * from Users;
select id, title, value from Blogs;
select id, feelURL, feelTitle from Feeds where id = 1;
Now im not very good at REGEX, but i want to get the table name from the mysql query. Could someone possibly create one for me with a little explanation.
Thanks,
Hi,
I'm starting a new project with symfony which is readily integrated with Doctrine and Propel, but I of course need to make a choice.... I was wondering if more experienced people out there have general pros and/or cons for going with either of these two?
Thanks a lot.
EDIT:
Thanks for the all the responses, useful stuff. There's no truly correct answer to this question so I'll just mark as approved the one that got the most popular up-votes.
Hi,
I am using the code below to upload an image through ftp
$sFile=$ftp_dir."/".$image_name;
$image=$database_row["image"];//image is store in database
$fh = tmpfile();
$fwrite($fh, $image);
$uploadFile = ftp_fput($conn_id, $sFile, $fh, FTP_ASCII);
fclose($fh);
The ftp is creating the file and has a size BUT the file i get is not an image.When try to open on image viewer i get error.
Before switch to ftp i had this code
$image=$database_row["image"];//image is store in database
$file = fopen( "images/".$image_name, "w" );
fwrite( $file, $image);
fclose( $file );
and was working fine, but now i have to use ftp.
What am i missing.
I've got my encryption function working properly however I cannot figure out how to get the decrypt function to give proper output.
Here is my encrypt function:
function Encrypt($data, $secret)
{
//Generate a key from a hash
$key = md5(utf8_encode($secret), true);
//Take first 8 bytes of $key and append them to the end of $key.
$key .= substr($key, 0, 8);
//Pad for PKCS7
$blockSize = mcrypt_get_block_size('tripledes', 'ecb');
$len = strlen($data);
$pad = $blockSize - ($len % $blockSize);
$data .= str_repeat(chr($pad), $pad);
//Encrypt data
$encData = mcrypt_encrypt('tripledes', $key, $data, 'ecb');
return base64_encode($encData);
}
Here is my decrypt function:
function Decrypt($data, $secret)
{
$text = base64_decode($data);
$data = mcrypt_decrypt('tripledes', $secret, $text, 'ecb');
$block = mcrypt_get_block_size('tripledes', 'ecb');
$pad = ord($data[($len = strlen($data)) - 1]);
return substr($data, 0, strlen($data) - $pad);
}
Right now I am using a key of test and I'm trying to encrypt 1234567. I get the base64 output from encryption I'm looking for, but when I go to decrypt I get a blank response.
I'm not very well versed in encryption/decryption so any help is much appreciated!!
Greetings all, I'm looking for a more efficient way to grab multiple users without too much code redundancy.
I have a Users class, (here's a highly condensed representation)
Class Users {
function __construct() { ... ... }
private static function getNew($id) {
// This is all only example code
$sql = "SELECT * FROM Users WHERE User_ID=?";
$user = new User();
$user->setID($id);
....
return $user;
}
public static function getNewestUsers($count) {
$sql = "SELECT * FROM Users ORDER BY Join_Date LIMIT ?";
$users = array();
// Prepared Statement Data Here
while($stmt->fetch()) {
$users[] = Users::getNew($id);
...
}
return $users;
}
// These have more sanity/security checks, demonstration only.
function setID($id) { $this->id = $id; }
function setName($name) { $this->name = $name; }
...
}
So clearly calling getNew() in a loop is inefficient, because it makes $count number of calls to the database each time. I would much rather select all users in a single SQL statement.
The problem is that I have probably a dozen or so methods for getting arrays of users, so all of these would now need to know the names of the database columns which is repeating a lot of structure that could always change later.
What are some other ways that I could approach this problem? My goals include efficiency, flexibility, scalability, and good design practice.
Im using the Zend Lucene however Im have a little trouble. I wish to query the index for the exact tring so page_name IS test123, not any fuzzy match.
Currently I have:
$hits = $index-find('page_name:"test123"');
And advice appreciated, thanks!
Yes I'm a n00b!
Now thats out of the way, I have the following code:
$page=3;
$i=1;
while($i<=$pages) {
$urls .= "'"."http://twitter.com/favorites.xml?page=" . $i ."',";
$i++;
}
What I need to create is this array:
$data = array('http://twitter.com/favorites.xml?page=1','http://twitter.com/favorites.xml?page=2','http://twitter.com/favorites.xml?page=3');
How can I produce an array from the 'while' loop?
Hello, can't understand mysql error:
UPDATE static_pages SET order = " Some
new data 222222
"Database error: You have an error in
your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near 'order = "
$query = 'UPDATE someTable SET '.$key.' = "'.$value.'"';
Here is $key = order; $value = 'new data 222222';
There is such keys in table: order, prices, contacts. Each of these updates well except the 'order'. Why?
Hi guys,
I've got this code
mysqli_query ( $userdatabase,
'CREATE TABLE `user_'.$emailreg.'` (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
IP varchar(10),
FLD1 varchar(20),
FLD2 varchar(40),
FLD3 varchar(25),
FLD4 varchar(25),
FLD5 varchar(25) )' );
echo ( mysqli_error ($userdatabase) );
that works fine on my localhost, but when I upload it to the server, it starts giving me a "Incorrect table name '[email protected]'" error. any idea?
Thanks!
My website has premium videos, for which users have to pay to watch it. I am sending a random user name and password to the user's email id when the payment is completed. Then I want to assure no more than one user use that login credentials simultaneously. For that I use a login_status column in database table with login credentials and change it to 1 when one user login and change to 0 when user log out. But the problem is, if the user close browser or network connection loss may happened will not update database. Then login_will be 1 undefinitely and no one can use that login credentials again.
Is there any idea to accomplish my task?
I hate that google can not search for symbols. I saw this in some sample code and wondered why there is an @ sign before the readfile function:
@readfile($filename);
What does it mean different to without an @ symbol?
I have this two arrays:
$arr1=array( array("id" => 8, "name" => "test1"),
array("id" => 4, "name" => "test2"),
array("id" => 3, "name" => "test3")
);
$arr2=array( array("id" => 3),
array("id" => 4)
);
How can i "extract" arrays from $arr1, where id have same value in $arr2, into a new array and leave the extracted array also in a new array, without taking into account key orders?
The output i am looking for should be:
$arr3=array(
array("id" => 8, "name" => "test1")
);
$arr4=array( array("id" => 4, "name" => "test2"),
array("id" => 3, "name" => "test3")
);
Thanks
I have a function which gets the ids of all children of a parent from my DB. So, if I looked up id 7, it might return an array with 5, 6 and 10. What I then want to do, is recursively find the children of those returned ids, and so on, to the final depth of the children.
I have tried to write a function to do this, but I am getting confused about recursion.
function getChildren($parent_id) {
$tree = Array();
$tree_string;
if (!empty($parent_id)) {
// getOneLevel() returns a one-dimentional array of child ids
$tree = $this->getOneLevel($parent_id);
foreach ($tree as $key => $val) {
$ids = $this->getChildren($val);
array_push($tree, $ids);
//$tree[] = $this->getChildren($val);
$tree_string .= implode(',', $tree);
}
return $tree_string;
} else {
return $tree;
}
}//end getChildren()
After the function is run, I would like it to return a one-dimentional array of all the child ids that were found.
Hi,
My tables are named in a plural form - Models / Entities, is there a way to make the generated classes named Model / Entity?
(Don't know if this is relevant, but I'm using Propel as the ORM)
Thanks.
I have an array of file-path strings like this
videos/funny/jelloman.wmv
videos/funny/bellydance.flv
videos/abc.mp4
videos/june.mp4
videos/cleaver.mp4
fun.wmv
jimmy.wmv
herman.wmv
Is there a library or easy way I can get to a data structure json or xml? Something like this: (I see there are a lot of snippets available for traversing actual folders, but again, I just have strings.)
{
files:{
file:[
{
filename:'fun.wmv'
},
{
filename:'jimmy.wmv'
},
{
filename:'herman.wmv'
}
],
folder:{
foldername:'videos',
file:[
{
filename:'abc.mp4'
},
{
filename:'june.mp4'
},
{
filename:'cleaver.mp4'
}
],
folder:{
foldername:'funny',
file:[
{
filename:'jelloman.wmv'
},
{
filename:'bellydance.flv'
}
]
}
}
}
}