space-delimited token at character position X in a string?

I am writing HTML content dynamically, loading it from a database. However, I want the content to include some escape characters that the PHP will search and process before sending it to the echo statement. I have not had a problem locating the escape code… For example, if the HTML content contains “#ESC” I use
[php]while(strpos(my_string,"#ESC"))
{
$position=strpos(my_string,"#ESC");
/fill in with code which eventually replaces the #ESC with something else/
}[/php]
Which gives me the character position of the #. Which is great, but the actual token is “#ESCX”, where X is a 1-4 digit number. I need to find the value of that number, and then replace “#ESCX” with HTML content based on the value of X.

What I really need is to be able to extract a substring beginning at a specific character position in a string, delimited by the space character (or whatever). This would allow me to extract “#ESCX”, which I could then easily strip off the “#ESC” part and rewrite the entire token to be replaced with content based on the value of X.

Or is there a completely different way to go about this?

Sponsor our Newsletter | Privacy Policy | Terms of Service