John,

Two inter-dependent problems:
1 a means of identifying a cipher within the text
2 a means of replacing the cipher with HTML code

1 there are a limited number of graphics formats (.GIF, .JPG, .PNG, etc) and the 
number you are prepared to contemplate
may be even shorter. Thus it would not be difficult to use the filetype as a means to 
trigger a RegExp - and thus have
no need for a "label mechanism" at all.

2 I'm finding RegExps a bit hairy too. However there are a number of illustrations 
'out there', eg in PHP and Perl web
site articles, and I'm sure there are some you could borrow/amend - I'm coming up to 
needing one fairly similar if you
want to 'trade'/division of labor.

Now I just know you're going to say that so far I've dealt with just the first 
component of [bird.gif,this is a bird] -
and just like every Canuck, you'd be right (or at least that's how the rest of us 
humor you(s))! First let's restate
that cipher as

   space+bird.gif"this is a bird"

where "space+" is at least one character of them immediately prior to the file name. 
Now you can see that the very same
RegExp that recognises/pulls out the graphic filename, should also be able to pull out 
the alt-text, because that is
enclosed within quotes (ie just as the HTML will require it). Because the quotes 
(could even offer the user/author a
choice of single or double!) are paired, and the first is immediately after the 
filename, you won't have problems with
other quoted strings getting caught up/misinterpreted!

It takes a warped mind...

Warped enough for you?
=dn


----- Original Message -----
From: "John A. Grant" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: 18 October 2001 17:11
Subject: [PHP] parsing a string


> 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 text
>
> I 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 text
>
> Crossing 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to