ereg_replace with unser defined function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello all.

Is it possible to have a user defined function for the replacement within an ereg_replace (like preg_replace_callback)? I am working on a script that converts html pages with metric data into imperial data. My script takes text strings containing one or more instances of e.g. "123 mm", "321 mm", "123 kg", "123 cm2" and so on. The script searches the string with a pattern like:
"([[:digit:]]+|[[:digit:]]+\.[[:digit:]]+)([[:blank:]]?)(mm)"

When the script finds an instance, it stores the matches into an array - ereg ( $pattern, $textstring, $matches )

The replacement (for mm) looks like:
round ( ( $matches[1] * 0.039370079 ), 1 ) . $matches[2]  . "in"

Everything is working great accept when the string contains more than one instance for example of the metric unit mm. In that case, all instances of "xy mm" will be replaced with the first occurrence.

So, a text like:

"The product is 230 mm tall, 120 mm thick and 340 mm wide" will output as "The product is 9.1 in tall, 9.1 in thick and 9.1 in wide" - because the replacement string is based / calculated on the first occurrence 230 mm.

Alternatively, is there a way to limit ereg_replace to only replace one instance at a time?

Hopefully I am not too confusing...

regards,

/frank

ps. of course I have searched the manual and asked Google - no luck ds.


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux