相关疑难解决方法(0)

在imagettftext()函数中从右到左读取文本字符串

我知道这个问题可能听起来很奇怪,但我很担心我为什么来找你...

我想用imagettftext()从右到左而不是从左到右写一个文本字符串; 功能

我在手册中读到了角度变量控制它,它说0角度意味着从左到右,所以我尝试了180,360但没有任何反应

我需要用什么角度来让它从右到左书写

我正在写一个带有支持希伯来字符的font.ttf的希伯来文本字符串

<?php   
$white = imagecolorallocate($background, 255, 255, 255);
$fontfile = "davidtr.ttf";
$string = "??????";
imagettftext($background, 12, 360, 3, 17, $white, $fontfile, $string);

?>
Run Code Online (Sandbox Code Playgroud)

我也使用了这个函数strrev(),

$white = imagecolorallocate($background, 255, 255, 255);
$fontfile = "davidtr.ttf";
$string = strrev("?????");
//imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
imagettftext($background, 12, 0, 3, 17, $white, $fontfile, $string);
Run Code Online (Sandbox Code Playgroud)

现在文字搞砸了图像上的一些字母是白色的盒子

然后我用这个功能:

function utf8_strrev($str){
   preg_match_all('/./us', $str, $ar);
   return join('',array_reverse($ar[0]));
}
Run Code Online (Sandbox Code Playgroud)

它对我帮助很大,但现在它也扭转了整数

$string = "??? 65 ???";
echo …
Run Code Online (Sandbox Code Playgroud)

php imagettftext

15
推荐指数
1
解决办法
1455
查看次数

StrRev()Dosent支持UTF-8

我正在尝试制作一个替代阿拉伯语文本的代码,以支持非阿拉伯语支持的程序
,因为我需要在替换后反转文本,但它显示一些垃圾内容而不是想要的结果

这是代码:

<?php
$string = "???? ??";
echo "$string <br>";
$Reversed = strrev($string);
echo "<br><b>After Reverse</b><br><br>";
echo "<br> $Reversed";
?>
Run Code Online (Sandbox Code Playgroud)

结果:

???? ??

After Reverse


??? ????
Run Code Online (Sandbox Code Playgroud)

我需要它是它的方式,但逆转?不是垃圾!!

php reverse utf-8 unicode-string

8
推荐指数
1
解决办法
3467
查看次数

针对给定单词(UTF-8)的N个字的优化正则表达式

我正在尝试找到一个优化的正则表达式来返回另一个的N个单词(如果可用)以构建摘要.字符串是UTF-8,因此"单词"的定义大于[az].用作参考词的字符串可以位于单词的中间,也可以不直接用空格包围.

我已经得到了以下有效但看起来实际上是贪婪和窒息时,在另一个周围寻找超过6-7个字:

/(?:[^\s\r\n]+[\s\r\n]+[^\s\r\n]*){0,4}lorem(?:[^\s\r\n]*[\s\r\n]+[^\s\r\n]+){0,4}/u
Run Code Online (Sandbox Code Playgroud)

这是我为此而构建的PHP方法,但是我需要帮助让正则表达式变得不那么贪婪并且可以处理任意数量的单词.

/**
 * Finds N words around a specified word in a string.
 *
 * @param string $string The complete string to look in.
 * @param string $find The string to look for.
 * @param integer $before The number of words to look for before $find.
 * @param integer $after The number of words to look for after $find.
 * @return mixed False if $find was not found and all the words around otherwise.
 */
private function …
Run Code Online (Sandbox Code Playgroud)

php regex pcre utf-8

6
推荐指数
1
解决办法
872
查看次数

用问号替换无效的UTF-8字符,mbstring.substitute_character似乎被忽略了

我想用引号替换无效的UTF-8字符(PHP 5.3.5).

到目前为止,我有这个解决方案,但删除了无效字符,而不是被'?'取代.

function replace_invalid_utf8($str)
{
  return mb_convert_encoding($str, 'UTF-8', 'UTF-8');
}

echo mb_substitute_character()."\n";

echo replace_invalid_utf8('éééaaaàààeeé')."\n";
echo replace_invalid_utf8('eeeaaaaaaeeé')."\n";
Run Code Online (Sandbox Code Playgroud)

应输出:

63 // ASCII code for '?' character
???aaa???eé // or ??aa??eé
eeeaaaaaaeeé
Run Code Online (Sandbox Code Playgroud)

但目前产出:

63
aaaee // removed invalid characters
eeeaaaaaaeeé
Run Code Online (Sandbox Code Playgroud)

有什么建议?

你会用另一种方式(preg_replace()例如使用?)

谢谢.

php utf-8 character-encoding mbstring

5
推荐指数
1
解决办法
2万
查看次数

希伯来字符串反向打印

我试图echo 这一行:

$mother_name = "?????? ????????"; 
echo strrev($mother_name);
Run Code Online (Sandbox Code Playgroud)

结果是: ????????? ???????

怎么了?我从哪里得到这个?符号。当我尝试echo从字符串中提取单个字符时,我也会?得到例如$mother_name[0]

php hebrew right-to-left

-1
推荐指数
1
解决办法
614
查看次数