How to modify specific parts within an html file?

Asked

Viewed 77 times

2

I am loading an html file and would like to modify urls within it so that the system recognizes the actual path of each file that 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’t do it. Someone can help me??

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

// 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"); ?>"> 
  • Hello, I can explain the problem better ?

  • @Edilson wrote there at the end of the question something that should summarize. Thank you for your attention.

  • Do you just want to change the urls within href? There is something in common among all the urls that you want to change?

2 answers

0

Dear, you can do this with the Notepad++ https://notepad-plus-plus.org/download/v7.3.3.html

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

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

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

Hug.

0

Using the sed gets like this:

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

Where:

html file = Your file you want to change the urls

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

Exit:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.