-2

I can only paste the text as it is (I can add some function around the text however before echoing it) between the echo ''; apostrophes - how can I insert the text in a way that it does not break the code?

Thanks!

EDIT:

Snippet from the code:

else {
echo '
<p>The place you're at, something "cute" you notice about her,</p> 
';
Allar
  • 85
  • 9
  • 2
    `I can only paste the text as it is `...why, exactly? That doesn't seem to make much sense on the face of it – ADyson Oct 06 '21 at 16:53
  • 1
    https://www.php.net/manual/en/language.types.string.php – Sammitch Oct 06 '21 at 16:58
  • "Copy/paste" is not a program concern, that's a programmer concern. As in the programmer has to use their fingers to do it. But you are also refusing to use your fingers to make the data acceptable to the program, which is odd. Perhaps you should clarify what your difficulty is. – Sammitch Oct 06 '21 at 17:01
  • I am using a third party program that generates the html page that has the "echo" function in it for displaying the html text. I can manipulate the template - add code etc to it but I can't manipulate the text itself beforehand - only via code - put some function around it etc.. – Allar Oct 06 '21 at 17:11
  • Why do you then need to paste that into a PHP program though? Why not write a PHP program to read whatever you need from this HTML file? – ADyson Oct 06 '21 at 17:21
  • I have a third party program that takes in a template html page and then takes in the text from a text file as is. The program generates a .php page that has html code in it and then php code in-between. I have what if sentence and it needs to echo html code as a result with the text in it (which has lot's of ', "", - etc signs" – Allar Oct 06 '21 at 17:23
  • Added an example from the code – Allar Oct 06 '21 at 17:35
  • please voice your concerns in the dedicated support channels of that third party software. Stackoverflow is about concrete programming questions, compare with the help section. If you're concerned about how to write PHP, see the PHP manual for the syntax you have to follow to not see syntax or parser errors. – hakre Oct 06 '21 at 17:38
  • So basically what you're saying is that this program incorrectly imports the data into the code it generates, without encoding it, and then you want to paste over it with a correct version? – ADyson Oct 06 '21 at 17:58
  • Yeah, the program doesn't encode the text first because it was not designed to be echoed in a php file but rather generate html files. – Allar Oct 06 '21 at 18:01
  • So why can't you manipulate the text in the file before you pass it through the 3rd party program? That isn't clear. – ADyson Oct 06 '21 at 19:01
  • That's what I decided to do now as a last resort. – Allar Oct 06 '21 at 19:13

1 Answers1

1

If you only have apostrophes, use echo "your text here";. If you only have double quotes, use echo 'your text here';. If you have both, you will need manipulate your string beforehand one way or another, or use another source than pasting directly in the instruction (pulling it from a file, for example).


EDIT:

If you can change the HTML:

else {
echo '
<p>The place you\'re at, something "cute" you notice about her,</p> 
';

If you can't, you'll need the PHP changed to pull the contents from somewhere else (a file, for example).

Saphir
  • 618
  • 5
  • 11
  • This seemed to not echo the text at all as if when I view the page source code after the page is displayed in browser non of the text is shown inbetween "echo" tags. – Allar Oct 06 '21 at 17:12
  • Maybe I'm not understanding what you're trying to do exactly. But `echo "your text with ap'o'strophes here";` should display `your text with ap'o'strophes here` correctly, for example. – Saphir Oct 06 '21 at 17:14
  • I have a third party program that takes in a template page and then takes in the text from a text file as is. The program generates a .php page that has html code in it and then php code in-between. I have what if sentence and it needs to echo html code as a result with the text in it (which has lot's of ', "", - etc signs" – Allar Oct 06 '21 at 17:18
  • @Allar It might help if you edit your original question to include whatever HTML and PHP code this third party program uses or generates or whatsoever. – Saphir Oct 06 '21 at 17:20
  • Edited the post – Allar Oct 06 '21 at 17:26
  • @Allar That won't be sufficient to help. We're going to need actual code or something tangible to understand what you're facing. – Saphir Oct 06 '21 at 17:29
  • Added an example from the code – Allar Oct 06 '21 at 17:35
  • @Allar Check the edit to my answer. – Saphir Oct 06 '21 at 17:40
  • @hakre Oh you're right, my apologies. – Saphir Oct 06 '21 at 17:44
  • @Saphir: No problem. – hakre Oct 06 '21 at 17:47