Edit a page


#1

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>

#2

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?


#3

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);

#4

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