Jump to content

Recommended Posts

I have two questions, first



<?php
$text = "a iKo SaioT eeee";
$fonts = "a|i|u|e|o";
$newText = preg_replace("#([$fonts].+?(?=[^$fonts![:space:]]))#us", '<b>$1</b>', $text);
echo $newText;
?>

Will be like (a iKo SaioT eeee). Not (a iKo Saioeeee). Why the last eeee letter does not change bold? And when $text = "a" The result does not turn into bold too.


I need without space too. Because if I put space in array a|i|u|e|o|[:space:]. It will be like this <b>e</b><b>e</b><b>e</b><b>e</b> will be separate. And if i using #([$fonts]?(?=[^$fonts![:space:]]))#us without .+, first and last, fonts not being bold


 


Second, how to convert this code into jquery



$newText = preg_replace("#([$fonts].+?(?=[^$fonts![:space:]]))#us", '<b>$1</b>', $text);

Cause $fonts is arrays not same in php


 


 


You should explain what you want to achieve, not how you think it should be done. The entire approach is just weird, and you cannot expect us to deduce the search pattern from a bunch of incorrect regexes.

 

Let's start with a high-level description: Where on your site are you using those patterns, and what is their purpose?

Edited by Jacques1
  On 7/22/2017 at 12:18 AM, Jacques1 said:

You should explain what you want to achieve, not how you think it should be done. The entire approach is just weird, and you cannot expect us to deduce the search pattern from a bunch of incorrect regexes.

 

Let's start with a high-level description: Where on your site are you using those patterns, and what is their purpose?

 

 

If i using

preg_replace('/['.$fonts.']/i', '<b>$1</b>', $text);

The result will be like this, right? a iKo Saioeeee but if you click right and inspect. 

You can see <b>a</b> <b>i</b>K<b>o</b> S<b>a</b><b>i</b><b>o</b>T <b>e</b><b>e</b><b>e</b><b>e</b> 

Being separated by spaces

 

But different from using ^$fonts![:space:]

To be <b>a</b> <b>i</b>K<b>o</b> S<b>aio</b>T eeee

 

Why i using exeption space? Cause Arabic script is continuous

If using ^$fonts![:space:] to be like <b>مَنْ جَاءَ بِا</b>

If not <b>م</b><b>َ</b><b>ن</b><b>ْ</b> <b>ج</b><b>َ</b><b>ا</b><b>ء</b><b>َ</b> <b>ب</b><b>ِ</b><b>ا</b>

Not same مَ نْ جَ اءَ بِ ا = مَنْ جَاءَ بِا

 

But this problem, like my question in post

Why the last eeee letter does not change bold? And when $text = "a" The result does not turn into bold too.

Edited by ARITABACAN

Can you read? I'm not interested in your weird regex gymnastics for now. They don't clarify anything, no matter how many times you repeat them. What I want is an explanation of the overall goal. The big picture, not the technical details.

 

Maybe you can understand this better: Let's say I'm a user of your website. An ordinary guy without any programming experience. Now, what does the feature you're trying to implement do for me? Why should I care about it?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.