replacing once with ereg_replace
| From: | lisi | Date: | Mon, 19 Jan 2004 10:21:31 +0000 |
| Subject: | replacing once with ereg_replace | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-32491@lists.php.net to get a copy of this message | ||
I have a problem with two possible solutions, I'm just not sure how to do either one.
I have a number of pages and their links stored in a MySQL db. The links are stored without the leading slash (i.e. animals/birds/birds.htm). $PHP_SELF returns the link with the leading slash (i.e. /animals/birds/birds.htm).
I need these two strings to match. There are two ways to do this:
1) Solution: Remove the leading slash from $PHP_SELF
Problem: How do remove only the first instance of the slash with ereg-replace and leave the others? Or is there another function that would do this? This may be obvious but I didn't see it in the documentation.2) Solution: Add the leading slash to each entry in the db (MySQL)
Problem: How do I do this with a query without having to change each one manually? I know I can change the link field using UPDATE but how would I tell MySQL to change the entry to / + entry? Each entry is obviously different. Using a plus makes MySQL think it's mathematical addition and sets the field to 0. The field type is varchar.Thanks in advance for any suggestions! -Lisi