The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Regex Help

I am having the database table with say 100 records.
I want to display the records sorted by title field.
How I want to display the records is that

A

All the titles starting from A
----
-----

B

All the titles starting from B
----
-----

and so on

I am having array as

PHP Code:

$alpha_array=array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");$i=0;while($row=@mysql_fetch_array($result)){$title=$row['title'];//Here i want to match the first character of $title with $alpha_array[$i]//if matches then display the alphabet and then records that start with that //alphabet$id=$row['id'];$i++;}

I would use ORDER BY Title in your query. This way you only have to check the first character of the title.
Be sure to trim the Titles before inserting these records in the table, so you won't have any whitespace characters at the beginning of the Title.
It would be best to group special characters too.

It is possible to reduce the functions required to pull the character.
Php allows us to walk through strings just as it was an array, character by character. This is the preferred method to use if possible as it is lightning fast.