Read css with php

-1

I was wondering if there was any way to read a css file with php and put the values in input.

For example: I have an input of type text that is called color and in the css I have a line that is called .Cabecera. Would there be any way to put the css text in that input?

This is the code that I have at the moment, but it reads all the css and puts it in a textarea.

$archivo = fopen($Ruta,"r") or exit;//indico archivo y que voy a hacer un read (r)
    while(!feof($archivo)) {
    $Mensaje .= fgets($archivo);
    }
fclose($archivo);

<textarea name="Contenido" id="Contenido" style="width: 99%; height: 99%; resize: none;"><?=$Mensaje; ?></textarea>

I just want to read line by line and put it in different text type input.

    
asked by Killpe 02.02.2018 в 18:11
source

3 answers

1

If it's the opposite and I do not get it wrong, you do not need PHP:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <title>Hello, world!</title>
        <style>
            .color {
                height: 200px;
                width: 200px;
                border: 2px solid #000000;
            }
            .verde {
                background-color: #00ff00;
            }
            .verde.claro {
                background-color: #005500;
            }
            .azul {
                background-color: #0000ff;
            }
            .azul.claro {
                background-color: #000055;
            }
            .rojo {
                background-color: #ff0000;
            }
            .rojo.claro {
                background-color: #550000;
            }
        </style>
    </head>
    <body>

        <div class="container">
            <div class="row">
                <div class="col-sm-offset-1 col-sm-2 color azul claro"></div>
                <div class="col-sm-offset-2 col-sm-2 color verde claro"></div>
                <div class="col-sm-offset-2 col-sm-2 color rojo claro"></div>
            </div>
            <div class="row">
                <div class="col-sm-offset-1 col-sm-2 color azul"></div>
                <div class="col-sm-offset-2 col-sm-2 color verde"></div>
                <div class="col-sm-offset-2 col-sm-2 color rojo"></div>
            </div>
            <div class="row">
                <div class="col-sm-offset-1 col-sm-10">
                    Haz clic en una caja de color: <input type="text" id="color_seleccionado">
                </div>
            </div>
        </div>

        <script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
        <script>
            $(function() {
                $(".color").click(function(e) {
                    $("#color_seleccionado").val($(this).css("background-color"));
                });
            });
        </script>
    </body>
</html>
    
answered by 03.02.2018 / 16:30
source
0

Let's see if it helps:

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html>
<head>
    <title>CAMBIAR COLOR</title>
    <meta http-equiv="Content-Type" content="txt/html; charset=utf-8" />
</head>

<body>
<h2>Cambiar color</h2>
    <p>Ingrese un color con el formato: xxxxxx, donde las xxxxxx pueden ser 0-9 y a-f</p>
    <form id="form" method="post" name="form" action="insertar.php">
        <p>Color: <input type="text" name="valor">

        <input type ="submit" value= "CAMBIAR VALOR">
        <input type="reset" value="LIMPIAR CAMPO">

    </form>

</body>
</html>

insert.php

<?php
if (!isset($_POST['valor']) || $_POST['valor'] == null){
    die('Escriba un color valido');
}

$valor = $_POST['valor'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html>
<head>
    <title>MUESTRA</title>
    <meta http-equiv="Content-Type" content="txt/html; charset=utf-8" />
</head>

<style type="text/css">
html {
    background: #<?php echo $valor; ?>;
}
</style>

<body>
<h2>Hola mundo</h2>

</body>
</html>
    
answered by 02.02.2018 в 20:11
0

If you can and it's very simple, the only thing you have to do is from your css code in the php file (index.php for example) use one and that's it, the value you have saved in the variable can be read in the css.

I hope it serves you Greetings

    
answered by 03.02.2018 в 17:41