0

I have the following HTML:

<aside>
    <p class="opentime">10 - 16</p>
    <p class="clocknote">Hours</p>
</aside>

After the 10 and the 16, I want the following code to be added:

<span>00</span>

so that it look like this:

<aside>
    <p class="opentime">10<span>00</span> - 16<span>00</span></p>
    <p class="clocknote">Hours</p>
</aside>

The span tag should be inserted after only the p tags with the class opentime.

Is there any PHP code to make this possible?


The actual code which is in the PHP is the following:

<?php $main_r_t = $pages->find('response_times/main/') ?>
<?php $r_t = $pages->find('response_times/times.txt') ?>

<aside>
   <p class="opentime"><?php echo $r_t->mo_time_1() ?></p>
   <p class="clocknote"><?php echo $main_r_t->clock() ?></p>
   <p class="opentime"><?php echo $r_t->mo_time_2() ?></p>
   <p class="clocknote"><?php echo $main_r_t->clock() ?></p>
</aside>

And the text file looks like:

mo_time_1: 10 - 12
----
mo_time_2: 13 - 19
----
1
  • 1
    How are you generating the HTML at the moment? Commented May 10, 2013 at 18:51

2 Answers 2

1

If you want to do it in pure PHP (I have no idea what the capabilities/limitations of Kirby are), you could do something like this:

$mo_time = $r_t->mo_time_1();
$time = explode(" - ", $mo_time);
echo "<p class='opentime'>" . $time[0] . "<span>:00</span> - " . $time[1] . "<span>:00</span></p>";

This isn't tested and does no error checking... That's up to you :)

Sign up to request clarification or add additional context in comments.

5 Comments

It worked! Thank you very much! You only forgot the $ before r_t in the first line :)
Oh jeez... That's what happens at the end of the day :) Glad it worked for you... You should be able to just use it inside of the explode() function to save some memory as well... I just assign it to a variable for readability... $time = explode(" - ", $r_t->mo_time_1());
Can I assign this 3 lines of code to one variable like `<?php echo $time ?>' to not every time write the 3 lines?
@projektalex you would be much better off writing a function for this and then pass your object to the function, returning the formatted string.
Thank you. I understand now that it is better to leave some more code but to understand how it works.
0

Do this

var text = $(".opentime").html();

var splitString = text.split(" ");
var newstr = splitString[0]+"<span>00</span>"+"-"+splitString[1]+"<span>00</span>";

$(".opentime").html(newstr);

2 Comments

Is this possible with php?
I do not want to use Jquery on all of my sites. I only want to use it for the gallery section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.