Jump to content

PHP Alternative to CDML 'Break' encoding?


This topic is 7207 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I'm working through converting our CDML pages to PHP, and with CDML I am using the 'Break' encoding for properly displaying text field content that may contain paragraphs (eg. [FM-Field: myField, Break]). This allows for paragraphs in a FM text field to at least look like paragraphs on a web page, even if semantically they're not.

However, using PHP all I get is one large block of text, irrespective of how it was formatted in FileMaker. Now, I realise that this is normal behaviour, but how do I go about replicating the CDML Break encoding functionality with PHP? I thought about searching for hard returns and replacing them with a <p> tag, but can't seem to figure out how to do it.

Anyone done this before?

Cheers,

Kevin

Link to comment
Share on other sites

Apologies for replying to myself here, but I've come up with a solution that should work, but doesn't with FileMaker (the script relies on FX.php).

  

<?php 

			$string = chr(13);

			$text = ($value['description'][0]);

			$description = str_replace($string, "</p><p>", $text);

			echo	"<p>" . $description . "</p>";

			echo "</div>n";

		}

		?>

If I use similar code on a predefined block of text that has the odd hard return in it, it works beautifully. But when applied to FM output via FX.php (which is in turn via XML), it doesn't work. I'm guessing that either FM strips out hard returns before generating the XML output, or FX does it on receiving it. Either way I'm stumped again.

Anybody got any ideas?

Cheers,

Kevin

Link to comment
Share on other sites

Well, this is beginning to become a habit ...

Anyway, I've solved the issue and thought for the sake of thoroughness I'd detail the solution here. In the code in my previous post, I changed this: $string=chr(13); to this: $string=chr(10) . chr(10);, which now works. It seems that OS X may use ASCII 13 (carriage return) as a hard return, but FM6U on the same platform uses ASCII 10 (line feed) ...

Strictly speaking, there's no need for the extra chr(10), but it more closely replicates CDML's Break encoding by converting 2 consecutive hard returns to valid <p> tags, without putting in empty paragraphs (which it does if you only use one).

Cheers,

Kevin, with apologies for running my own thread!

Link to comment
Share on other sites

This topic is 7207 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.