I
I
Igor Vasiliev2017-08-08 01:37:33
JavaScript
Igor Vasiliev, 2017-08-08 01:37:33

What is the best solution for converting words to html code?

Hello.
--
There are records in the database, such as: 1.jpg|s-500.jpg
and: 6000-z|1000|2000
----
there are a lot of records, so you can REDO them for a whole month, so as not to engage in nonsense, I thought, it would be better to just wrap "images" and "values" in html code.
The first thing I decided was to remove the separating stick, and replace it with a comma, and then wrap it in double quotes to make an array out of this, however, in order to convert, for example, to json, these numbers or words need to be added some value to get : Then you can easily store at least 50 images in one cell of the table, in the form: Then it remains to load and update in the action in the form of a json string, how to get data from json - I know.
$list = array(1=>"1.jpg", 2=>"s-500.jpg");
{"1":"1.jpg","2":"s-500.jpg"}
But how to convert:
1.jpg|s-500.jpg
to Without crutches, I can’t imagine, the same somehow needs to be done with the values, you can then use the tag method to write and overwrite data like: 1.jpg|s -500.jpg The latter will be links. The dilemma is how best to work with such data, because now they are stored in this form, and are separated only by a stick, without spaces. For a very long time, in pure php, I output such data from a text document, they were just stored in the form: It was enough to wrap the name in an html tag, and remove the sticks to display a record, in my case, each individual word, by some miracle should end up in: and in:
{"1":"1.jpg","2":"s-500.jpg"}

Имя|Сообщение|Дата
<?=Html::img('слово из БД', ['alt' => 'image'])?>

<?=Html::a('слово из БД', '/ssilka/'.слово из БД, ['class' => 'myclass']);?>

=============================================
Tell me how to be in such a situation, how is it possible, or how best to do it, through which programming language? In what direction to move?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Exploding, 2017-08-08
@Exploding

In $data type string from loop

$data = explode("|", $data);
$data = json_encode($data);

All. $data is now json data

M
Maxim Timofeev, 2017-08-08
@webinar

You can redo them for a whole month

and you can make an action in 15 lines of code and do it in 10 minutes. The method, as suggested by Exploding , is only to make the base normal, to take all the records from the old one and transfer them correctly to the new one in a loop.
In yii, this is not a problem at all, you create a temporary action:
public function actionPerehrehyzchit(){
$old = OldModel::find()->all();
$errors = [];
  foreach($old as $one){
    $data = explode("|", $one->someAttr);
    foreach($data as $one_data){
        $new_model = new NewModel();
        $new_model->someId = $one->id;
        $new_model->imageName = $one_data;
        if(!$new_model->save()){
           $errors[$one->id][] = $new_model->errors;
        }
    }
  }
echo '<pre>';
print_r($errors);
echo '<pre>';
return 'я фсё, удали экшен';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question