Jump to content
Sign in to follow this  
ARITABACAN

How using preg_replace overall on a arrays

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


 


 


Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

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.