Is there an easy way (preferably with htaccess and mod_rewrite) to force the browser to always access a site with the www. prefix (adding it automatically where necessary?)
Thx.
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
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?
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
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 have this form for inputting the birthday in html. But I only have a single column for storing it in wampserver(Column Birthday).
<select title="- Select Month -" name="mm" id="mm" class="" >
<option value="" SELECTED >Month</option>
<option value="1" >Jan</option>
<option value="2" >Feb</option>
<option value="3" >Mar</option>
<option value="4" >Apr</option>
<option value="5" >May</option>
<option value="6" >Jun</option>
<option value="7" >Jul</option>
<option value="8" >Aug</option>
<option value="9" >Sep</option>
<option value="10" >Oct</option>
<option value="11" >Nov</option>
<option value="12" >Dec</option>
</select>
<input title="Day" type="text" onkeypress="return isNumberKey(event)" name="dd" value="" size="1" maxlength="2" id='numbers'/ >
<input title="Year" type="text" onkeypress="return isNumberKey(event)" name="yyyy" value="" size="1" maxlength="4" id='numbers'/> </td>
Do you have any idea on how I can place those 3 values in the same column?Please help
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.
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 there. I am using preg_replace to add a link to keywords if they are found within a long HTML string. I don't want to add a link if the keyword is found within h1 tags or strong tags.
The below regex nearly works and basically says (I think): If the keyword is not immediately wrapped by either a h1 tag or a strong tag then replace with the keyword that was matched, as a bolded link to google.
$result = preg_replace('%(?!<h1>)(?!<strong>)\b(bobs widgets)\b(?!<\/strong>)(?!<\/h1>)%i','<a href="http://www.google.com"><strong>$1</strong></a>', $result, -1);
(the reason I don't want to match if in strong tags is because I am recursing through a lot of keywords so don't want to link an already linked keyword on subsequent passes)
the above works fine and won't match:
<h1>bobs widgets</h1>
It will however match the keyword in the following text, because the h1 tag isn't immediately either side of the keyword:
<h1>Here are bobs widgets for sale</h1>
I need to make the spaces either side optional and have tried adding \s* but that doesn't get me anywhere. I'd be very grateful for a push in the right direction here.
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.
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'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.
$_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,
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.
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 All,
I've created a form that stores free text fields into a MySQL database.
All works fine and the data is displayed back as intended when viewed. Except for one niggle.
In an attempt to prevent malicious attacks I have used mysql_real_escape_string to remove any unwanted code from the input.
However, I need to be able to preserve hyperlinks and basic html.
For example, I want to store the following:
<p align="left">Please follow this <a href="link.html">link</a></p>
But the link is being stored as \"link.html\" as the quotes are being escaped.
How can I preserve this link and other html?
Many thank
TT
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 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 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'
}
]
}
}
}
}