Edit a page

I can view the contents of a file using…
http://lukesspot.com/indus_links/populate_rack.php?id=1
with

$svg = show_source('racks/cabinet_'.$rack_id.'.php');
echo $svg;	

How do I add some code just after the second

<rect>

(just before all the)

<text>

this seems like the function I want
http://php.net/manual/en/function.file-put-contents.php

But how can I specify where to put the code?

Not sure if it’s the best solution but just an idea:
You could explode the contents of the file by line:

$lines = explode(PHP_EOL, $fileContents);

and then use array_splice to insert lines where ever you want,
and finally implode back the lines:

$fileContents = implode(PHP_EOL, $lines);

I don’t think you want to use show_source aka. highlight_file. Though it may display as XML, it does not return XML. It returns some characters converted to entities. eg &lt; instead of <

If splitting into an array won’t work for you, you should be able to use “reader” and “writer” as long as you are working with valid non-entitized XML.

http://php.net/manual/en/book.xmlreader.php

http://php.net/manual/en/book.xmlwriter.php

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.