How to modify specific parts inside an html file?

2

I'm loading an html file and would like to modify urls inside it so that the system recognizes the actual path of every file the html is trying to access, so I have several different urls:

<link rel="stylesheet" href="assets/vendor/font-awesome/css/font-awesome.css">      
<link rel="stylesheet" href="assets/vendor/magnific-popup/magnific-popup.css">      
<link rel="stylesheet" href="assets/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.css">

// Function
public function index()
{
    $layout = $this->uri->segment(2);
    $arquivo = read_file("/public_html/application/views/porto/{$layout}.php");

I would like to wrap these urls with <?php echo base_url("urlaqui") ?> but I can not do this. Can anyone help me ??

Explaining better, I would like to modify the urls that are in the html, and what I have and the final result follow:

// O que eu tenho ...
<link rel="stylesheet" href="assets/vendor/font-awesome/css/font-awesome.css">

// O que eu preciso ...
<link rel="stylesheet" href="<?php echo base_url("assets/vendor/font-awesome/css/font-awesome.css"); ?>"> 
    
asked by anonymous 24.03.2017 / 14:22

2 answers

0

Dear, you can do this with notepad ++ link

Open your file with it and give crtl + H, in the search mode choose "regular expression".

Localizar: (href=")(.*)(">)

Substituir por: <?php echo base_url\(""\); ?>

Hug.

    
24.03.2017 / 17:27
0

Using sed looks like this:

sed -r 's/href="(.*)"/href="<?php echo base_url(""); ?>"/' arquivo-html >> novo-html

Where:

  

html-file = Your file you want to change urls

     

new-html = New file created in the current directory with corrected urls.

Output:

<link rel="stylesheet" href="<?php echo base_url("assets/vendor/font-awesome/css/font-awesome.css"); ?>">      
<link rel="stylesheet" href="<?php echo base_url("assets/vendor/magnific-popup/magnific-popup.css"); ?>">      
<link rel="stylesheet" href="<?php echo base_url("assets/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.css"); ?>">
    
24.03.2017 / 18:06