Re: parsing a string
| From: | Mike Eheler | Date: | Thu, 18 Oct 2001 17:01:23 +0000 |
| Subject: | Re: parsing a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-71513@lists.php.net to get a copy of this message | ||
Beyond that, why not keep it conforming to HTML, and use an <IMG> tag, for example:
This is some text <img src="name.jpg" alt="Alt Text" processat="server">.
That way if you need to view the page "as-is" in a browser or whatever, it'd still look fine.. go grab yourself some good free html parser code, and analyse the options. If processat="server" then do your thing, and re-write the <img> tag. :)
Mike
Jason G. wrote:
Why don't you do something like this: <servimg:name.jpg:This is the alt text Buddy> Then search for a regx something like <servimg*> (I am not sure of the exact syntax). Then parse the found tag, generate your <img tag and replace the original tag with the generated tag. I hope it gives you some good ideas. -Jason Garber IonZoft.com At 12:11 PM 10/18/2001 -0400, John A. Grant wrote:I'm reading some HTML text from a file and echoing it to stdout. The HTML text contains <IMG> but I would rather have the server do the work of looking up the image size. I know how to lookup the image size with getimagesize(). My problem is in coming up with a good format for embedding a reference to the image in the text and then writing the code to parse it. So instead of this:here is some text <img src=bird.gif width=100 height=20 alt="this is a bird"> and here is more text and another image <img src=plane.gif width=123 height=23 alt="this is a plane"> and more textI would like to have something like this:here is some text [bird.gif,this is a bird] and here is more text and another image [plane.gif, this is a plane] and more textCrossing line boundaries is not an issue - each text string is complete. I need to be able to dump out the string until I see a reference to an image, then extract the name and alt text, handle it (by emitting <IMG>) and continue to echo text from the string until I encounter another image reference. My problem is in coming up with a syntax for this and then to write the code to extract the information. In the above example, I'm using the syntax:[filename,text]but it's conceivable that the HTML text might also contain[some plain text not related to images]so I thought about some of these:{filename,alt text} - not good, text might contain {plain text] @filename, alt text@ img(filename,alt text)Using the same @ delimiter at each end might make it easier to use explode() to split the text. But perhaps img(filename,text) is more elegant, but it might need more skills than I have in using regex to recognize it and extract it. Also I need to figure out how to extract and echo the plain text around it. Any ideas are appreciated. Thanks. -- John A. Grant * I speak only for myself * (remove 'z' to reply) Radiation Geophysics, Geological Survey of Canada, Ottawa If you followup, please do NOT e-mail me a copy: I will read it here -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net