URL encode is used to encode certain characters within a URL. It's not used to encode all characters and certainly isn't a means of encryption.
24 URL encoded is 24.
URL encode is used to encode certain characters within a URL. It's not used to encode all characters and certainly isn't a means of encryption.
24 URL encoded is 24.
I suggested a foreach
loop because it removes the complexity.
It's more complicated with a while loop. You'll need to look into the use of the current
, next
and perhaps end
functions for arrays.
I've used a foreach loop instead, but something like the following should work.
$month = null;
foreach($data as $row)
{
if(is_null($month) || $month <> $row['month']) {
$month = $row['month'];
echo "<strong>{$month}</strong><br />";
}
echo "{$row['name']}<br />";
}
Are you using PHP 5.2 or above?
If so, you could use to validate the email address as a whole:filter_var('bob@example.com', FILTER_VALIDATE_EMAIL);
And then using strpos and substr extract the domain element and do a string comparison to restrict the domain.
I have used the same code on another part of the site and it works perfectly.
I don't see that you've reinitialised the $files
array anywhere. It could be populated with the results of the last time you used the code.
Add $files = array();
immediately after line 4.
If using a unique filename doesn't resolve the issue, you'll need to debug your code at each stage. To do this, you could write the upload progress for each image to a log file. E.g.
- Image uploaded (to temporary directory)
- Image extension allowed / disallowed
- Image filename
- Image moved to images directory
- SQL query
- Image inserted into database
This would then allow you to see where it's failing for each.
Are you getting any errors when uploading the files either on screen or in the server error log?
Do the images you're trying to upload exceed the filesize limit?
Are the 50 images appearing in the database?
Are the 50 images being successfully uploaded into your images directory?
Do you have permission from the third party site to use their content?
If so, could they not provide you with a data feed?
$string = 'username Membership Fee' or 'Username29473 Membership Fee';
$string = explode(' ', $string);
$username = $string[0];
You can get a list of the child taxonomies using the get_terms
function. Simply pass the current taxonomy value as the parent argument.
Why have you started a new thread, asking the same question when someone has already taken the time to respond to your first thread?
http://www.daniweb.com/web-development/php/threads/442914/suggestions-please
In order to log into the site, both your username and encrypted (yet unsalted) password are stored in an encrypted cookie that uses the same salt for everyone. So, even if you did gain access to the database, you wouldn't be able to do very much with it because you'd be unable to rebuild a usable cookie in order to log in.
Isn't the point that most hackers will attempt to find the raw passwords from the hashes stored in a compromised database using dictionary attacks and the like?
They'd then be able to login using the standard website login functionality.
Sorry, it should have been a comma to separate the arguments in array_merge not a plus.
It'll be limited because adding two arrays with a + overwrites duplicate indexes. array_merge doesn't overwrite duplicate numeric keys.
According to the PHP docs, money_format is unsupported on Windows environments. Are you running Windows?
As an alternative, you could try number_format.
number_format(0, 2); // 0.00
number_format(1.00, 2); // 1.00
number_format(1.2, 2); // 1.20
When looking for a book, make sure you buy one for the correct version of the framework. Zend 1.8 is rather old.
The framework is on version 2.0.5, and was heavily rewritten for the release of version 2 to include the new PHP 5.3 features. Version 2 is therefore not backwards compatible with any previous versions.
@diafol hit the nail on the head.
I was going to suggest that if you were unable to remove the blank lines from your CSV, that you instead test for their presence when iterating through the data.
If the blank lines are truly empty, i.e. there are no spaces or anything, then adding something like the following should solve the issue. See lines 11 and 12.
<?php
$handle = fopen('csv.csv', 'r');
$row_count = 0;
echo '<html><body><table>';
// Iterate through each line of CSV file
while(($line = fgetcsv($handle)) !== false)
{
// Skip line if empty
if(! $line)
continue;
$row_class = $row_count % 2 ? '' : 'dark';
$cell_count = 0;
echo "<tr class=\"{$row_class}\">";
// Iterate through each line value
foreach($line as $value)
{
$cell_class = $cell_count % 2 ? '' : 'light';
echo "<td class=\"{$cell_class}\">" . htmlspecialchars($value) . '</td>';
$cell_count += 1;
}
echo '</tr>';
$row_count += 1;
}
echo '</table></body></html>';
fclose($handle);
That's what you posted in your OP, which consequently you said isn't what you want.
Can you put the data into context? What is the relationship between table 1 and 2 for you to need a left join rather than inner join? Without explaining that, I can only assume the result you want is:
SELECT a.col1 FROM table1 a LEFT JOIN table2 b ON (a.id = b.table_a_id)
UNION
SELECT b.col1 FROM table1 a LEFT JOIN table2 b ON (a.id = b.table_a_id)
However, this will include NULL values where there isn't a joining value in table b.
Here is a snapshot of the csv viewed in excel... it skips a line in the csv, so it would skip a line as seen on the site.
So you want a blank line? Because your original post alludes to that being the problem.
What exactly are you trying to do, and what exactly is the problem?
Line 30 probably should not be commented out, unless I've overlooked a closing </tr>
tag somewhere else.
It may also be helpful if you could post a sample of your CSV file too, just to check that all lines contain the same number of comma separated values and no blank lines.
You need to use a join. If you only want results where they appear in both tables, you need an inner join.
I'm not sure why you need to query both tables when you're passing the user id to the query. You could simply select the data directly from the users table using the id.
However, please find an example join query below:
SELECT `u`.`id`, `u`.`username`
FROM `users` `u`
INNER JOIN `posts` `p` ON (`p`.`user_id` = `u`.`id`)
WHERE `u`.`id` = 22
Seems $object->{'23'}
will work, but only if the index is a string not an integer.
E.g.
$object_1 = new stdClass;
$object_1->id = 12345678;
$object_1->name = 'Sharer Name';
$object_1->offset = 0;
$object_1->length = 14;
$object_1->type = 'user';
$object_2 = new stdClass;
$object_2->id = 87654321;
$object_2->name = 'Page Name';
$object_2->offset = 23;
$object_2->length = 14;
$object_2->type = 'page';
$object = new stdClass;
$object->{0} = $object_1;
$object->{23} = $object_2;
echo '<pre>'; var_dump($object->{'23'}->{'id'}); echo '</pre>';
@diafol - your idea of casting the object to an array seems the most likely to succeed if the OP is unable to change the structure of the object.
@GliderPilot - I do not believe that you can access an object property which has a numeric name in that way.
Instead you'd need to use: $object->{'23'}[0]->id
Use preg_split to tokenize the string based on invalid characters. Iterate through and check whether each resulting token is a valid email address. If it isn't remove it from the array.
<?php
$string = 'person-1@here.com, person_2@there.net; person.3@wayoverthere.com';
#$string = '"Jane Le-Doe" <john.ledoe@somewhere-interesting.com>';
#$string = 'jane.doe@ hello ,;;;; me@home.no<>where';
#$string = 'to b @ not 2 be';
#$string = 'this_email@is_obviously_not_valid';
$emails = get_all_emails($string);
echo '<pre>'; print_r($emails); echo '</pre>';
/**
* Extract valid email addresses from string.
*
* @param string $string
* @return array
*/
function get_all_emails($string)
{
$emails = preg_split('/[\s,;\<>]/', $string);
foreach($emails as $index => $email)
{
if(! filter_var($email, FILTER_VALIDATE_EMAIL))
unset($emails[$index]);
}
return $emails;
}
In your example, the category data is stored in an attribute, rather than within the node itself.
You therefore need to use the XPath: /product[1]/categories/category/@path
where the @ shows you want to target an attribute.
$string = 'tel7051636mitsubishilanceryear00fulloptionmoteurdohcinjectionbodykitjantecosmicpourplusdereseignementtel7787425seriousbuyeronlypricers475000chevroletaveols';
preg_match_all('tel([\d]+)', $string, $matches);
print_r($matches);
Hi Brad,
In answers to your questions:
Yes, it's fine to do it that way.
If you're consistent in the way you delimit the subcategories in your database field, e.g. using a semi-colon, then there's no reason why you couldn't use a single row. I would be tempted to use an array to group your products by subcategory before outputting the overview though.
E.g.
$grouped_products = array();
// Iterate through product results
while ($product = $stmt->fetch())
{
// Split sub-categories on ;
$sub_categories = explode('; ', $product['sub']);
// Append product to array indexed by sub-category
foreach($sub_categories as $sub_category)
$grouped_products[$sub_category][] = $product;
}
// Iterate through grouped products
foreach($grouped_products as $sub_category => $products): ?>
<div class="li_sub"><?php echo $sub_category; ?></div>
<ul>
<?php foreach($products as $product): ?>
<li><?php echo $product['name']; ?></li>
<?php endforeach; ?>
</ul>
<?php endforeach;
I tried writing an ORM layer using static methods and PHP 5.2 and it simply didn't work, because it didn't support late static binding.
In the end, I had to settle for the approach used in the Yii framework, whereby you use a static method to create an instance of the object, so you can then use inherited instance variables instead.
E.g.
class User extends Model
{
protected $_table = 'users';
public static function model($class = __CLASS__)
{
return parent::model($class);
}
public function find($id)
{
// Find by id
}
}
class Model
{
public static function model($class)
{
return new $class;
}
}
$user = User::model()->find(1);
If you can use PHP 5.3, then you can use late static binding, hence the inherited value static properties can be accessed in the parent class.
You can seed the RAND()
function with an integer value.
If you were to use the current hour of the day as the seed for example, then your query would return the same results in the same order for a whole hour, and then change during the subsequent hour, and so on.
E.g.
SELECT *
FROM `juarez`
ORDER BY RAND(HOUR(NOW()))
LIMIT 1
A VARCHAR[255] field should allow sufficient space for the URLs.
If else statements are executed base on the condition specified. Looking at your code, whenever the amount is greater than 0, it will always match the first if block. if the amount isn't greater than 0, it will always match the else block.
You might consider trying a switch statement instead and use the value of $_POST['form']
where you select your currency to determine the output. E.g.
$amount = isset($_POST['amount']) ? $_POST['amount'] : 0;
$currency = isset($_POST['form']) ? $_POST['form'] : false;
$value = 0;
if(! $amount) {
echo 'Please enter an amount';
}
else {
switch($currency) {
case 'taka':
$value = ($amount * 80) . 'Tk';
break;
case 'rupe':
$value = ($amount * 20) . 'Rup';
break;
case 'inr':
$value = ($amount * 10) . 'Inr';
break;
default:
echo 'Please select a currency';
break;
}
}
You were checking if the username was equal to the boolean returned by isset()
, not the username stored in the session. Your logic was just a little out.
@rotten69 - because you can tell the web server to parse HTML files for PHP before serving the content to the browser.
Browsers do not understand PHP, even in PHP files. It's a server side scripting langauage. So even in PHP files, the file is parsed and only resulting output sent to the browser.
If you haven't come across this resource already, I found it useful:
http://www.velvetblues.com/web-development-blog/how-to-parse-html-files-as-php/
It talks about the type of handler you need to use based on whether you have one or multiple versions of PHP installed. If using multiple, you need to explicitly specify application/x-httpd-php5 .html
, but there are a couple of other workarounds to try too.
I ended up using the following in a .htaccess file:
AddHandler application/x-httpd-php .html
And the following in a HTML file:
<h1>Hello <?php echo 'World'; ?></h1>
The isset()
function is used to check whether a variable, or in this case, the username index of the $_SESSION
array is set. It only returns true or false, hence why your comparison on line #2 is failing.
To fix the issue, you could use:
// If user is logged in and username matches post username
if(isset($_SESSION['username']) && $_SESSION['username'] == $post['username']) {
echo "<a href='delete.php?id={$post['id']}'>Delete</a>";
echo "<a href='edit.php?id={$post['id']}'>Edit</a>";
}
You can round the value using the round()
function. The second parameter is the number of decimal places you'd like the value rounded to.
<?php
// Find radius
$radius = isset($_GET['radius']) ? (float)$_GET['radius'] : 0;
// Calculate area of circle with specified radius
$area = round($radius * $radius * M_PI, 7);
echo $area;
If you're still not getting the answer you want, you might want to replace the M_PI
with your own value, as the constant is likely more precise to more decimal places than your chosen value.
It really isn't clear from the code you've posted what your starting array structure or desired finished array structure should be.
At a guess, you can do the following:
$array = array();
$array['key1'] = 'one';
$array['key2'] = 'two';
print_r($array);
/*
array(
'key1' => 'one',
'key2' => 'two',
)
*/
If that's incorrect, what exactly are you trying to achieve?
SELECT `s`.*
FROM `students` `s`
INNER JOIN `department` `d` ON (`d`.`departmentName` = `s`.`department` AND `d`.`userid` = '{$Userid}')
WHERE `s`.`registrationNo` = '{$RegNo}'
You're using a sub-query for the department. It needs to be wrapped in brackets. E.g.
$query = "select registrationNo,name,fatherName,cnic,gender,discipline,department,admissionSession,email,password,address,domicile,contactNo,status,currentEmployer,designation,salaryInfo,totalExperience,lastOrganizationname,organizationAdd,organizationPhno,organizationEmail,Remarks from students where registrationNo='$RegNo' AND department = ($Dep)";
Alternatively, you could write the query using a join, thus avoiding the need for a sub-query entirely.
The easiest method would be to pass the video name, real or alternate, to the page where it will be played, and then to embed the video. E.g.
<a href='uploads/upload/browseplayer.php?video=funny'>funny</a>
Then within the browseplayer.php
script, using the $_GET['video']
parameter, query the database, find the actual file name and output it in the source attribute.
Okay, well it looks like you're most of the way there already.
At the moment, you're uploading the file and using the original name of the uploaded file - that's the $_FILES['file']['name'];
part.
Instead, what you need to do is replace that with the new file name. E.g.
$file_name = 'funny'; // New unique file name
move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/upload/{$file_name}.mp4");
Or if you move line 36 to just after line 12, you could do something like:
$video_name = mysql_real_escape_string($_POST['videoname']);
move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/upload/{$video_name}.{$extension}");
You could always use a robots.txt file to disallow Google bots indexing the click counter links.
I e had a look at Yii before too and thought it looked pretty good.
The ORM is excellent. So much so I even ported it to Zend.
What level of education are you talking about here?
If it's a college graduation project then you shouldn't be working on simple ideas. The project has to merit the qualification it will contribute towards.
How about something like:
Where are you setting the variable value?
I was asking where you were setting $model
. You need to set a value before you can use it.
One thing thats kinda intersting is the model = '%s'.
The placeholders allow for the creation of prepared SQL statements. This helps to prevent SQL injection attacks.
mysql_insert();
Ignore me. That should have been mysql_query()
. I don't usually use the native MySQL functions in PHP. I usually use a database object, so they're wrapped in different method names.
$result = $html->find('div[id=res]', 0);
$nav_bar = $html->find('div[id=navbar]', 0);
$result = str_replace($nav_bar, '', $result);
$result = str_get_html($result);
foreach($html->find('nobr') as $nobr)
$result = str_replace($nobr, '', $result);
$result = str_get_html($result);
$result = str_get_html($result);
echo "$result";
Tip for the future... RTFM :)
Can you post the content of $displaybody
and $matches
so I can see what the source code looks like and what is or isn't being matched??
If you just want to remove the whole of the navbar, can you not just use str_replace
, rather than preg_replace
/ preg_match
??
Perhaps something like (I've not used the library before, so am guessing at how it might work).
$html = file_get_html('http://www.example.com');
$result = $html->find('div[id=res]', 0);
$nav_bar = $html->find('div[id=navbar]', 0);
$result = str_replace($nav_bar, '', $result);
$result = str_get_html($result);
How about something like:
<?php
session_start();
$_SESSION['lang'] = 'en';
$content=<<<CONTENT
<p>{{Dyma destun||Here's some (more) text}}</p>
<p>{{Cymru||Wales}}</p>
...
CONTENT;
function translate($content)
{
$lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en';
$pattern = '/\{\{([^\|\|]*)\|\|(.*)\}\}/';
$replacement = ($lang == 'cy') ? '$1' : '$2';
return preg_replace($pattern, $replacement, $content);
}
echo translate($content);
You're passing an id with the value 0
.
If you read the definition for the function empty
, you'll see that 0 is one such value that evaluates as being empty. It will therefore never return true.
Can you not use a non-zero value for the id? If not, you could consider testing for the presence of an integer instead.
@rotten69 and @simplypixie
'and' and 'or' operators are both perfectly acceptable in PHP.
http://php.net/manual/en/language.operators.logical.php