Domanda

I need to generate imacro syntax for the user to be able to copy from the browser screen.

Since iMacro is using <SP> for spaces I need to replace database values that have spaces with with <SP>.

This isn't working because the browser recognizes <SP> as HTML character.

$srtnew = str_replace(" ","<SP>",$string);

Any suggestions?

È stato utile?

Soluzione 2

You need to do:

header("Content-Type:text/plain");

before you output it.

This tells the browser to output the content as a pure text format and not as html.

Of course you could also do it like this:

$srtnew = str_replace(" ",htmlentities("<SP>"),$string);

If you have many tags you should just set the header if you only want to output that code in order to let your users copy them.

More information about setting headers in PHP: http://www.php.net/manual/de/function.header.php

Altri suggerimenti

You can use the HTML entities for angled brackets (&lt; and &gt;):

$srtnew = str_replace(" ","&lt;SP&gt;",$string);

Alternatively, you can use PHP's htmlentities() to encode the brackets:

$srtnew = str_replace(" ",htmlentities("<SP>"),$string);

Working example (PhpFiddle)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top