Search found 212 matches

by chris
Mon Nov 05, 2012 8:39 pm
Forum: SQL
Topic: How to get the id inserted by Auto increment
Replies: 2
Views: 40684

Re: How to get the id inserted by Auto increment

I have good results with

mysql_query("INSERT INTO table (product,date_1) values ('item','$today')");
$lastid=mysql_insert_id();

Basically it gets the id generated from the previous insert.

If it doesn't work,
You can try to get it from table status:
$result=mysql_query("SHOW TABLE STATUS LIKE ...
by chris
Fri Sep 28, 2012 12:44 pm
Forum: PHP
Topic: Solved: Regular expression for url
Replies: 3
Views: 76521

Re: Regular expression for url

On this site you get a good overview of several patterns,
with there pro's and con's:
http://mathiasbynens.be/demo/url-regex
by chris
Fri Sep 28, 2012 12:00 pm
Forum: PHP
Topic: Solved: Regular expression for url
Replies: 3
Views: 76521

Re: Regular expression for url

I find the following pattern works well for me

"@((https?://|ftp://)([-\w\.]+)+(:\d+)?(/([\w/_\.\-\+\~\=\:]*(\?\S+)?)?)?)@"

$pattern=array("@((https?://|ftp://)([-\w\.]+)+(:\d+)?(/([\w/_\.\-\+\~\=\:]*(\?\S+)?)?)?)@");
$replace=array("[Somtehing]\\1");
$str=preg_replace($pattern,$replace,$string ...
by chris
Wed Sep 26, 2012 7:34 pm
Forum: PHP
Topic: php convert text date
Replies: 1
Views: 58145

Re: php convert text date

strtotime() does its job well, but it need to be in the correct order.
day month year

Use a function to switch the dates:
function switch_date($str)
{
//split string
$arr=explode(' ',$str);
//put in correct order
$new_str=$arr[2].$arr[1].$arr[0].$arr[3];
return date('Y-m-d', strtotime($new ...
by chris
Fri Sep 21, 2012 7:23 pm
Forum: PHP
Topic: PHP Warning: preg_match(): Compilation failed: missing ) at
Replies: 5
Views: 121729

Re: PHP Warning: preg_match(): Compilation failed: missing

There is probably a character in $c_line[1] that breaks your regular expression ($pattern).

You can use preg_quote() to escape special characters.

Your code should look something like this:
$pattern="/\b".preg_quote($c_line[1])."\b/i";
if(preg_match($pattern,$text)) $countries[]=$c_line[0];
by chris
Tue Sep 18, 2012 12:40 pm
Forum: PHP
Topic: PHP Warning: preg_match(): Compilation failed: missing ) at
Replies: 5
Views: 121729

Re: PHP Warning: preg_match(): Compilation failed: missing

Sound like a problem in your regex.

If you post some of you code, we could check it out.
by chris
Tue Sep 18, 2012 12:38 pm
Forum: PHP
Topic: Sort multi-array
Replies: 1
Views: 55473

Re: Sort multi-array

I usually create my own function and use it with usort:

function num_sort($a,$b)
{
return strcmp($a[2],$b[2]);
}

And call it with
usort($multi_array,"num_sort");

The array is in this case the second field named '2' (But you can give it any name you want).
$multi_array['key1'][1]="value 1 ...
by chris
Tue Sep 18, 2012 12:08 pm
Forum: PHP
Topic: How do I search in multi-array
Replies: 1
Views: 54971

Re: Ho do I search in multi-array

You can create your own function:

Code: Select all

function search_multi_arr($needle,$haystack)
{
  foreach ($haystack as $key => $val)
  {
    if ($val[1] === $needle) return $key;
  }
  return null;
}
You can call the function with

Code: Select all

$key=search_multi_arr($search_value,$multi_array);
by chris
Thu Sep 13, 2012 3:19 pm
Forum: MySQL
Topic: Solved: convert MySQL db from Latin1 to UTF8
Replies: 7
Views: 233198

Re: convert MySQL db from Latin1 to UTF8

If you still have problems.
you can also use, in php:

Code: Select all

mb_internal_encoding("UTF-8");
It tells php to do everything in UTF-8 character-set.
by chris
Thu Sep 13, 2012 2:17 pm
Forum: MySQL
Topic: Solved: convert MySQL db from Latin1 to UTF8
Replies: 7
Views: 233198

Re: convert MySQL db from Latin1 to UTF8

You can test if your server and browser are "speaking" in UTF-8 with printing the following string.
$test='Iñtërnâtiônàlizætiøn';
echo $test."\n";

If you don't see the string correctly,
try adding the HTML line:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

In PHP you can ...