Hi,
Can anyone give me starting place of how to go about replacing a part of a string with data from a database.
I have a database table called 'person' which contains people's names:
Table person:
id
firstnames
surname
(ie: '1', 'Tom', 'Cruise' / '2', 'Steven', 'Spielberg')
and I have a string:
"Superstar [Tom Cruise] is at his charismatic best in director [Steven Spielberg]'s terrific race against time thriller."
I wish to alter the parts wrapped in square braces to something like: ... best in director <a href="details.php?id=2">Steven Spielberg</a>'s terrific race ...
I know about the ereg_replace function, but I'm not sure of how to go about extracting the correct id number and placing it in the replacement string.
I figure that somehow I need to extract the contents of the square braces (Steven Spielberg), split them at the space and then search the database for " firstnames LIKE 'Steven' AND surname LIKE 'Spielberg' " and then select the id number for the returned result and insert it into the replacment string .... and do this for each occurance of the squared braces.
Does that sound right? Does anyone know of a better/easier solution and can anyone give me an idea of how to do this.
Any help would be very much appreciated. I don't expect people to 'do' this for me, but rather explain what I need to do (much like I have done above) so that I might try to work it out myself. I find I learn better this way.
Many thanks,
Geoffo