Insensus 52 Junior Poster

I've placed an additional subpattern in the matching pattern which matches only the part of the link after the http://
It basically matches like this: ([url]http://(www.website.com[/url])) which sets the following back-references for the replacement

$1 = [url]http://www.website.com[/url]
$2 = [url]www.website.com[/url]
Cap'nKirk commented: spot on, thx +3
Insensus 52 Junior Poster

How about this

$text = preg_replace('/(https{0,1}:\/\/([\w\-\.\/#?&=]*))/', '<span class="tweet_links_intext"><a href="$1" target="_blank">$2</a></span>', $text);
Insensus 52 Junior Poster

How about this.

$string_exp = "/^[A-Za-z\x80-\x95 .'-]+$/";
Insensus 52 Junior Poster

At line 7 you specify the variable $path1 but in the copy function on line 11 you use $path which is undefined.
This produces the error.

Insensus 52 Junior Poster

By default PCRE regex patterns in PHP don't match newlines with . and maybe POSIX patterns do, I'm not sure.
But since you probably have newlines in your template file, I think changing the pattern to the following should solve your issues:

$header = preg_replace("/".$bodytag."(.*)/is", '', $temp);
$footer = preg_replace("/(.*)".$bodytag."/is", '', $temp);

Also there is probably an easier way to do this, without the need for regex, assuming I have the right idea of how your template file works.

$bodypos = strpos($temp, $bodytag);                   // Find the position of the %BODY%
$header = substr($temp, 0, $bodypos);                 // The length of the header is the same as the position of the %BODY%
$footer = substr($temp, $bodypos + strlen($bodytag)); // And the start of the footer is the position of the %BODY% plus it's length
Insensus 52 Junior Poster

Just add

$rows[$k] = array();

in between lines 7 and 8.

Insensus 52 Junior Poster

Are you perhaps including this file in another file?

What's on line 28 of /blam/login1.php?

Something I encountered a few days ago: Is your file perhaps saved as UTF-8 with BOM?

Insensus 52 Junior Poster

It would help if you'd also post the error but a first suggestion would be to use <?php as starting tag instead of your <? on line 1.

Insensus 52 Junior Poster

Well I think my approach is only limited by the physical MySQL limits which probably results in more than enough room for items unless your game goes really big.
But then you'd probably get some real programmers to do the job for you, eh. :p

Insensus 52 Junior Poster

What do you mean by hard coding something into a table?

Insensus 52 Junior Poster

This is just a suggestion but maybe it'll be the key to you figuring it out.

Keep an 'items' table containing all the items in your game with a structure like:
id, type, upgrades, owner
Then you could just fetch all items with a certain type and a certain owner enabling multiples of one item upgradable seperately.

Insensus 52 Junior Poster

Judging from the code you wrote I feel like you don't really know what you're doing.
So please make sure you understand my code instead of ignorantly copying it.

#include <iostream>
#include <time.h>

int main()
{
    time_t before = time(NULL);

    char input;
    std::cin >> input;

    //time_t after = time(NULL);
    //std::cout << difftime(after, before) << " seconds passed";
    std::cout << difftime(time(NULL), before) << " seconds passed";
}
Insensus 52 Junior Poster

Also, may I ask why you want to do this in the first place?

If it's for measuring the time the users takes to produce some input it's much easier to check the time before you ask for input, check it again right after input has been received and simply subtract the two.

Take a look at this if that is the case:
http://www.cplusplus.com/reference/clibrary/ctime/clock/
http://www.cplusplus.com/reference/clibrary/ctime/time/
http://www.cplusplus.com/reference/clibrary/ctime/difftime/

Insensus 52 Junior Poster
Insensus 52 Junior Poster

In the first file you set two variables with the username and password for MySQL.
When connecting however you don't use these variables but two constants.

Also, or die(mysql_error()) can be appended to any MySQL function, including mysql_connect.
If you would've done that, mysql_connect would throw the first error instead of mysql_select_db.

Insensus 52 Junior Poster

In connection.php you are connecting with MySQL functions but in Prepared_Statements.php you are trying to execute queries with the MySQLi functions.

Insensus 52 Junior Poster

Because 150.000 x 150.000 floats equals ~21GB of memory.
I don't think you have that much RAM in your computer.

Insensus 52 Junior Poster

I already mentioned above that ,if javascript is not a cool option ,then go for jquery.
Traffic control is must because otherwise it may reault to the server down.

Do you know that jQuery is actually a JavaScript framework and therefore if you switch off JavaScript you also switch of jQuery?
I guess you didn't.

Insensus 52 Junior Poster

If you have read this line above,you wouldn't have asked this ....
And about validations,it's better to use javascript or JQuery for this ,than using PHP because it must be done on client side otherwise it will just increase the load on your server.These are some of the basics that must be taken into considerations while programming.....
Hopefully it's clear...

Since we don't even know what his program is intended for I will take your comment as if you mean to apply it to every website that takes input from the user.

A simple counter-example would be a money booking site: What if someone disables JavaScript and inputs a value of -1000 to be booked from his account to someone else. Do you really think server load is what you should be worried about in that case?

Insensus 52 Junior Poster

If the link to the page is something.php?error=insertsomethinghere
then $_GET = insertsomethinghere

Header is explained by IIM and the errors are due to not checking whether the variables are set

isset($_GET['error'])

I only provided you with a basic outline of how you would program what you requested, I'm not here to do your work for you.

header("Location: form.php?error=$error");

This is to redirect the user to the same page..for more reference about header,click here...
And moreover...the code above is not required at all...
Just use javascript for the same....Click here to learn about different kinds of validation(These are called validations i.e., numeric input,or alha-numeric input etc)

If you read my earlier answer you wouldn't have mentioned JavaScript as it can be turned off and then where's your validation?

Insensus 52 Junior Poster

That is exactly what my code does.

If you however don't want the form to submit at all you obviously shouldn't use PHP to do the checking but JavaScript.
In that case, however, remember that JavaScript can be switched off and you'd still have to use PHP to check for numerals which means using my code.

Still I think it's very wise of you to say that I didn't understand your question when you don't understand the answer.


I'll try to break my code down to your level by providing an example.

The user enters:

first: a
second: b

My code on sign.php will do this:

$error = 0;
Is first a number? - No => $error += 1 //So $error is now 1
Is second a number? - No => $error += 2 //So $error is now 3
Is $error non-zero? - Yes => Send the browser back to the form but pass the error number $error along

On the form my code now produces the following:

//$_GET['error'] = 3;
Is the first bit set in $_GET['error']? - Yes => Print 'Invalid input!' after the first input box
Is the second bit set in $_GET['error']? - Yes => Print 'Invalid input!' after the second input box

Considering your response you probably don't know that 1 is written as 01 in binary, 2 as 10 and 3 as 11 which we use here to transfer the information about the input back to the …

Xufyan commented: <3 ! Xufyan +3
Insensus 52 Junior Poster

In short, this is what you do:

sign.php

$error = 0;
if(!is_numeric($val1))
	$error += 1;

if(!is_numeric($val2))
	$error += 2;

if($error != 0)
	header("Location: form.php?error=$error");

This sends the user back to the form and passes information about which field wasn't a numeral.
1 (01): The first is not a numeral
2 (10): The second is not a numeral
3 (11): Both are not a numeral
Note: Make sure there is NO output before the header function or you will get an error.

form.php

<form method="post" action="sign.php">
	<input type="text" name="first">
	<?php echo ($_GET['error'] & 1) ? "Invalid input!" : ""; ?>
	<select name="select">
	<option>+</option>
	<option>-</option>
	<option>x</option>
	<option>/</option>
	<option>%</option>
	<?php echo ($_GET['error'] & 2) ? "Invalid input!" : ""; ?>
	<input type="text" name="second">
	<input type="submit" name="submit" value="submit">
	</form>

Hope this is understandable.

Insensus 52 Junior Poster

Change line 11. from

$id = $_GET['id'];

to

$id = $_POST['id'];
karthik_ppts commented: hmmm +5
Insensus 52 Junior Poster

mysql_query returns a boolean false when the query fails so if you fix the query (to which the second error applies) the first will disappear also.

As for the second error: it's probably something to do with $UserID as the rest looks alright.
Maybe you could show us what the query looks like when it's executed? (echo $SQL)

Insensus 52 Junior Poster

Check out this function http://php.net/urlencode

Insensus 52 Junior Poster

Answering that question would be easier if you could state what it is exactly you're trying to achieve.
Saves us from trying to figure it out through your code.

Insensus 52 Junior Poster

If you want someone to look at your source code, why not post it in your topic to begin with?
It's why they invented the code-tag.

Insensus 52 Junior Poster

The / is escaped because it signifies the end (or start) of the pattern.
Only pattern modifiers can follow after that.

And there is no difference between those two.

Insensus 52 Junior Poster
$regex = '/^[0-9]{5,}\/[a-zA-Z]\.[0-9]{2,}$/';
Insensus 52 Junior Poster
bool pComp(int* a, int* b) { return *a < *b; }

vector<int*> pVec;
std::sort(pVec.begin(),pVec.end(), pComp);
Jsplinter commented: thank you +2
Insensus 52 Junior Poster

You're missing a . at line 46.

'"$_POST['fd_period']."'
'".$_POST['fd_period']."'
Insensus 52 Junior Poster

What you have now is:

10 => 0
11 => 1

I suspect you want:

9 => 0
10 => 1

Which I'd do like:

$ASoliderPercent = floor($attackerSoldiers/10);
Insensus 52 Junior Poster

I don't think it doesn't find it but your method of checking whether it has is wrong.
Instead try

if (inFile.is_open())
Insensus 52 Junior Poster

Ok I'm sorry I missed that.
But there's still an error in your MySQL query and you would've known had you executed it like this:

$result = mysql_query($query1) or die(mysql_error());

The problem is that since both your datatable and datatable2 contain a field numid, the WHERE numid='0010' is ambiguous as you don't specify if it's the numid from the first or second table.
Even though your query suggests that the results wouldn't differ I think this is the problem.

Insensus 52 Junior Poster

You can't do that because 5.0 is stored as 5.
There is nothing stored about how many insignificant zeroes you entered in your code.

Insensus 52 Junior Poster

This means your mysql_query returns a false because there's an error in your query.

Which is the result of line 11 because your query will look like:
select * FROM datatable LEFT JOIN datatable2 ON datatable.numid=datatable2.numid WHERE numid='$numid' AND
There is nothing following the AND which produces an error.

Insensus 52 Junior Poster

Why not use my solution?
It guarantees no two equal randoms and doesn't require database queries.

Insensus 52 Junior Poster
$rands = range(300, 10000);
shuffle($rands);

$random1 = array_pop($rands);
$random2 = array_pop($rands);
$random3 = array_pop($rands);
...
diafol commented: I like that :) +13
Insensus 52 Junior Poster

Ok I've think I figured out why your code doesn't work, but I don't think there's a way to do it exactly like you want to.

The problem is this:
The return type of union_set is the same type as given for the 5th argument, the OutputIterator.
In your case this means union_set returns a back_inserter_iterator<vector<int>> yet you want to assign this to a vector<int>::iterator.

The easiest way to fix this is by indeed removing the it = and simply using unionsetv.end() whenever you would've wanted to use it.

Insensus 52 Junior Poster

Quote from cplusplus.com
For the function to yield the expected result, the elements in the ranges shall be already ordered according to the same strict weak ordering criterion (operator< or comp).

Insensus 52 Junior Poster

Did you press the AJAX Examples link on the left?

Honestly, I think that site is all you'll ever need.
It's all I ever needed anyway.

Insensus 52 Junior Poster
Insensus 52 Junior Poster

I don't know what the purpose of this code is but it looks like they want the following set of selection rules:
sizeof(T1) > sizeof(T2): ResultT = T1
sizeof(T1) = sizeof(T2): ResultT = void
sizeof(T1) < sizeof(T2): ResultT = T2

With the alternative you suggested the selection rules would be:
sizeof(T1) > sizeof(T2): ResultT = T1
sizeof(T1) <= sizeof(T2): ResultT = T2

Insensus 52 Junior Poster
$rands = range(1,40);
shuffle($rands);

for ($i=0; $i<$numeroDeobjetos; $i++) {
  $usada[$rands[$i]] = true;
}
Insensus 52 Junior Poster

Line 139.

denominator /= b;

should of course be

denominator /= a;
Insensus 52 Junior Poster

Because the \ is the character used to escape things like quotes, it's not appropriate to use it on its own.

Use

std::cout << " \\ ";

instead.

Insensus 52 Junior Poster
bool playAgain = true;
cin >> playAgain;
while( (playAgain == 'Y' || playAgain == 'y' ));

Enough of a hint? :)

Insensus 52 Junior Poster

Again you are trying to get the value you want from the variable $data which does not contain the result of the query.

But

$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$row = mysql_fetch_array($query);
echo $row['ID'];

should work.

What this does is:
mysql_query: execute the given query on the database; returns a MySQL resource variable from which you can extract the actual result of the query.

mysql_fetch_array: read the next row (or false if there aren't any left) from the query-result given as an argument. This has to be a MySQL resource like the above function returns.
This returns an array containing the fields of the result for one row and since you'll never get more than one row you only have to call it once.

Now the $row should contain what you are looking for.

Insensus 52 Junior Poster

The query as I posted should be fine on itself, but in the code in your last post no query ever gets executed.

All you are doing right now is making a string $data which contains the query you want to send, and setting $id to the int-value of an undefined variable ($row doesn't exist in your code) which comes down to $id = 0.
So when echo-ing $data[$id] you should expect $data[0] to be echo'd which is the first character of the string $data which is an S.

Try understanding what this page reads under 2. Procedural style. It's about how to execute query's.

Insensus 52 Junior Poster

You can't include array variables in double-quote strings like that, this has to be done either of two ways:

// Connect to the database
    $dbc = mysqli_connect("localhost", "xxxxxxx", "xxxxxxxxx", "xxxxxxx");
	$data = "SELECT ID FROM user_registration WHERE username = '" .$_SESSION['username']. "'";
	$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
// Connect to the database
    $dbc = mysqli_connect("localhost", "xxxxxxx", "xxxxxxxxx", "xxxxxxx");
	$data = "SELECT ID FROM user_registration WHERE username = '{$_SESSION['username']}'";
	$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());

And don't forget to escape them first of course.